akhauriyash/Code-Regression huggingface dataset:
from collections import deque
n,m = map(int,input().split())
e = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)

ans = [-1]*(n)

q = deque([])

q.append((0,-1))
while q:
    now,bef = q.popleft()

    for nex in e[now]:
        if nex == bef:
            continue
        if ans[nex] == -1:
            ans[nex] = now+1
            q.append((nex,now))
print("Yes")
for i in ans[1:]:
    print(i)


Measured memory_bytes: 39972
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

s = arr_data[0][0]


print("Yes" if "AC" in s else "No")

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  REP(i,N/7+1){
    if((N-7*i)%4==0){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);


        for(int i = 1; i < 6; i++){
            int x = sc.nextInt();
            if(x == 0){
                System.out.println(i);
                return;
            }
        }

    }
}


Measured memory_bytes: 35664
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int n;
  cin >> n;
  int res = 0;
  for(int a = 1;a <= n;a++){
    for(int b = 1;a*b < n && b <= a;b++){
      if(a == b)res++;
      else res += 2;
    }
  }
  cout << res << "\n";
  


  return 0;
}

Measured memory_bytes: 3596
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

#list_num =  list(sys.stdin.readline().rstrip())

#print(list_num)

list_num = list(map(int, sys.stdin.readline().split()))

ab = str(list_num[0]) + str(list_num[1])

abr = math.sqrt(int(ab))

if(abr == int(abr)):
    print('Yes')
else:
    print('No')
# print(abr)


Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n , x) for (int i = (int)(x); i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 1; --i)
#define repBX(i, n , x) for (int i = (int)(n); i >= int(X); --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    char a;
    cin >> a;
    if (isupper(a))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define X first
#define Y second
#define fw(i, start, end) for (ll i = start; i < end; ++i)
#define fe(i, start, end) for (ll i = start; i <= end; ++i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define endl "\n"

vector<ll> v[100069];
// int vis[100069];
ll dis[100069];
ll par[100069];
void bfs(ll x)
{
    queue<ll> q;
    q.push(x);
    par[x] = 1;
    while (!q.empty())
    {
        ll fr = q.front();
        q.pop();
        for (auto it : v[fr])
        {
            if (par[it] == -1)
            {
                par[it] = fr;
                q.push(it);
            }
        }
    }
}

int main()
{
    FASTIO
    ll n, m;
    cin >> n >> m;
    fe(i, 1, m)
    {
        ll a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    memset(par, -1, sizeof par);
    bfs(1);
    ll fl = 0;
    fw(i, 2, n + 1)
    {
        if (par[i] == -1)
        {
            fl = 1;
            cout << "No" << endl;
            return 0;
        }
    }
    if (!fl)
    {
        cout << "Yes" << endl;
        fw(i, 2, n + 1)
        {
            cout << par[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 13096
#include<stdio.h>
#include<string.h>
int main(){
    char s[22];
    while(gets(s)){
        int len = strlen(s);
        for(int i = 0;i < len;++i){
            if(s[i] == ',') printf(" ");
            else printf("%c",s[i]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
using AtCoderBeginnerContest142.Questions;
using AtCoderBeginnerContest142.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest142.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var odd = (n + 1) / 2;
            yield return (double)odd / n;
        }
    }
}


namespace AtCoderBeginnerContest142
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest142.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest142.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,x,y,z,sum=0;
    vector<long long int>v;
    cin>>x>>y>>z;
    v.push_back(x);
    v.push_back(y);
    v.push_back(z);
    sort(v.begin(),v.end());
    for(i=0;i<2;i++)
    {
        sum=sum+abs(v[i]-v[i+1]);
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
using System;
using System.Numerics;

namespace AtCoderBegin
{
    class Program
    {
        static void Main(string[] args)
        {
			int k = int.Parse(Console.ReadLine());
			int num = 7;
			for (int i = 0; i < Math.Pow(10, 6); i++)
			{
				if (num % k == 0)
				{
					Console.WriteLine(i + 1);
					return;
				}
				num = int.Parse(num + "7") % k;
			}
			Console.WriteLine(-1);
		}
    }
}   


Measured memory_bytes: 46520
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let a = sc.chars();
    let b = sc.chars();
    put!((0..a.len() + b.len()).map(|i|
        if i % 2 == 0 { a[i/2] } else { b[i/2] }
    ).collect::<String>());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


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

int main(){
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    int x[N] = {0};
    for (int i = 0; i < N; i++)
    {
        x[0] += pow(-1,i)*A[i];
    }
    
    x[0] /= 2;
    for (int i = 1; i < N; i++)
    {
        x[i] = A[i-1] - x[i-1];
    }
    for (int i = 0; i < N; i++)
    {
        cout << 2 * x[i];
        if(i!=N-1) cout << " ";
        else cout << endl;
    }

}

Measured memory_bytes: 2048
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int main(){

	int N,tmp;
	vector<int> V;
	scanf("%d",&N);

	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	sort(V.begin(),V.end());
	if(V[0] != 1){
		printf("1\n");
		return 0;
	}

	ll sum = 0,ans = 0;

	for(int i = 0; i < V.size();i++){
		sum += V[i];
		if(i < V.size()-1 && V[i+1] > sum+1){
			ans = sum+1;
			break;
		}
	}

	if(ans == 0)printf("%lld\n",sum+1);
	else{
		printf("%lld\n",ans);
	}

	return 0;
}

Measured memory_bytes: 2816
n=int(input())
txy=[[0,0,0]]+[list(map(int,input().split())) for i in range(n)]

ans='Yes'
for i in range(n):
  dt=txy[i+1][0]-txy[i][0]
  dx=abs(txy[i+1][1]-txy[i][1])
  dy=abs(txy[i+1][2]-txy[i][2])
  if (dt-(dx+dy))%2!=0 or dt<dx+dy:
    ans='No'
    break
print(ans)

Measured memory_bytes: 28148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cout<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

void solve(int K,int N){
    if(K%2==0){
        cout<<K/2;
        rep(i,N-1)cout<<" "<<K;
        cout<<endl;
        return;
    }
    vector<int> res;
    rep(i,N)res.push_back((K+1)/2);
    rep(i,N/2){
        if(res.back()==1)res.pop_back();
        else{
            res.back()--;
            while(int(res.size())<N)res.push_back(K);
        }
    }
    rep(i,int(res.size())-1){
        cout<<res[i]<<" ";
    }
    cout<<res.back()<<endl;

}

int main(void){
    int K,N;
    cin>>K>>N;
    solve(K,N);
    return 0;
}


Measured memory_bytes: 3568
N, K = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(N)]
x = sorted(list(zip(*p))[0])
y = sorted(list(zip(*p))[1])
dic_x = {v: i + 1 for i, v in enumerate(x)}
dic_y = {v: i + 1 for i, v in enumerate(y)}
cum_sum = [[0] * (N + 1) for _ in range(N + 1)]
for i, j in p:
    cum_sum[dic_y[j]][dic_x[i]] = 1

for i in range(1, N + 1):
    for j in range(N):
        cum_sum[i][j + 1] += cum_sum[i][j]

for i in range(1, N + 1):
    for j in range(N):
        cum_sum[j + 1][i] += cum_sum[j][i]

ans = 10 ** 20
for l in range(N):
    for r in range(l + 1, N):
        for d in range(N):
            for u in range(d + 1, N):
                z = cum_sum[u + 1][r + 1] - cum_sum[d][r + 1] \
                     - cum_sum[u + 1][l] + cum_sum[d][l]
                if z >= K:
                    ans = min(ans, (x[r] - x[l]) * (y[u] - y[d]))
print(ans)

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,K;
int a[5050];
int dp[5050][5050];

bool culc(int c){
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    rep(i,0,N){
        rep(j,0,K){
            chmax(dp[i+1][j],dp[i][j]);
            if(i==c)continue;
            if(j>=a[i]){
                chmax(dp[i+1][j],dp[i][j-a[i]]);
            }
        }
    }
    rep(i,0,min(a[c],K)){
        if(dp[N][K-i-1]!=0)return true;
    }
    return false;
}

signed main() {
    cin>>N>>K;
    rep(i,0,N)cin>>a[i];
    sort(a,a+N);
    int l = -1, r = N;
    while (l+1<r) {
        int c=(l+r)>>1;
        bool ok=culc(c);
        if (ok) r = c; else l = c;
    }
    cout<<l+1<<endl;
    return 0;
}


Measured memory_bytes: 199552
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll k; cin >> k;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
    }
    REP(_, min(k, ll(50))){
        vector <ll> imos(n+1, 0);
        REP(i, n){
            imos[max(i-as[i], ll(0))]++;
            imos[min(1+i+as[i], ll(n))]--;
        }
        ll cnt = 0;
        REP(i, n){
            cnt += imos[i];
            as[i] = cnt;
        }
    }
    REP(i, n-1){
        cout << as[i] << " ";
    }
    cout << as[n-1] << endl;
    return 0;
}


Measured memory_bytes: 6300
def card_game():
    n = int(input())
    player1 = 0
    player2 = 0

    for _ in range(n):
        tmp = input().split()
        if tmp[0] > tmp[1]:
            player1 += 3
        elif tmp[0] < tmp[1]:
            player2 += 3
        else:
            player1 += 1
            player2 += 1

    print(f"{player1} {player2}")


if __name__ == "__main__":
    card_game()



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

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{


    lint n,d;
    cin >> n >> d;
    lint x[n][d];
    REP(i, n) {
        REP(j, d)
        {
            cin >> x[i][j];
        }
    }
    lint ans=0;
    lint sumdis = 0;
    double s;

    REP(i, n)
    {
        FOR(k,i+1,n){
            REP(j, d)
            {
               sumdis+=(x[i][j] - x[k][j]) * (x[i][j] - x[k][j]);
            }
            s = sqrt(sumdis);
            if (ceil(s)== floor(s))
            {
                ans += 1;
            }
            sumdis = 0;
        }
    
    }
    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;
	lint A[100010]={};
	lint B[100010]={};

	cin >> N;
	for(int i=1;i<=N+1;i++)
		cin >> A[i];
	for(int i=1;i<=N;i++)
		cin >> B[i];
	
	lint ans=0;
	for(int i=1;i<=N;i++)
	{
		lint tmp=max((lint)0,min(A[i],B[i]));
		ans+=tmp;
		A[i]-=tmp;B[i]-=tmp;
		tmp=max((lint)0,min(A[i+1],B[i]));
		ans+=tmp;
		A[i+1]-=tmp;B[i]-=tmp;
	}

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



Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N, K;

class SparseTable{
public:
    SparseTable(){}
    SparseTable(int *a, int n){
        init(a, n);
    }
    void init(int *a, int n){
        size = n;

        REP(i, size){
            table[i][0] = a[i];
        }

        int step = 1, done = 1;
        while(done < size){
            for(int i=0;i+done<size;i++){
                table[i][step] = table[i][step-1] + table[i+done][step-1];
            }
            ++step;
            done *= 2;
        }
    }
    int query(int l, int r){
        int n = r - l, step = 0, res = 0;
        while(n > 0){
            if(n & 1){res += table[l][step]; l += 1 << step;}
            n >>= 1;
            ++step;
        }
        return res;
    }
private:
    static const int MAX_N = 100000, MAX_LOG_N = 17;
    int table[MAX_N][MAX_LOG_N+1], size;
};

SparseTable st;
int A[100000];

int main(){
    while(std::cin >> N >> K, N){
        REP(i, N){
            std::cin >> A[i];
        }
        st.init(A, N);

        int res = -INF;
        for(int i=0;i+K<=N;i++){
            res = std::max(res, st.query(i, i+K));
        }

        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 8580
from collections import deque
import sys
input=sys.stdin.readline

def abc():
    global qqq
    for i in range(len(ppp)-1,0,-1):
        qqq=qqq*cmb(ppp[i],ppp[i-1])%mod
    return qqq

mod=10**9+7
MAX=2*10**5+100
g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
data=[[] for i in range(N+1)]
for A,B in AB:
    data[A].append(B)
    data[B].append(A)
parent=[0]*(N+1)
flag=[0]*(N+1)
child=[0]*(N+1)
parent[1]=-1
flag[1]=1
que=[1]
ddd=deque([])
while que:
    h=[]
    for u in que:
        for v in data[u]:
            if flag[v]==0:
                flag[v]=1
                h.append(v)
                parent[v]=u
                child[u]+=1
        if child[u]==0:
            ddd.append(u)
    que=h
#sizeは、子の数
size=[0]*(N+1)
#lstは、書く順番の総数
lst=[0]*(N+1)
while ddd:
    u=ddd.pop()
    size[u]=1
    qqq=1
    ppp=[]
    for v in data[u]:
        if v==parent[u]:
            child[v]-=1
            if child[v]==0:
                ddd.appendleft(v)
            continue
        else:
            size[u]+=size[v]
            if ppp:
                ppp.append(size[v]+ppp[-1])
            else:
                ppp.append(size[v])
            qqq=qqq*lst[v]%mod
    lst[u]=abc()
que=deque(data[1][:])
#iを根としたときの答え
ans=[0]*(N+1)
#lslsは親方向の場合の数
lsls=[0]*(N+1)
ans[1]=lst[1]
lsls[1]=1
while que:
    #uに対する場合の数を求める
    u=que.pop()
    par=parent[u]
    ppp=N-size[par]
    num=lst[u]*cmb(size[par]-1,size[u])
    qqq=lst[par]*pow(num,mod-2,mod)%mod
    qqq=qqq*lsls[par]*cmb(ppp+size[par]-size[u]-1,ppp)%mod
    lsls[u]=qqq
    ppp=N-size[u]
    qqq=qqq*cmb(N-1,size[u]-1)*lst[u]%mod
    ans[u]=qqq
    for v in data[u]:
        if v==par:
            continue
        else:
            que.appendleft(v)
for i in range(1,N+1):
    print(ans[i])



Measured memory_bytes: 143076
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100100100;//10^17
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n, ll mod){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % mod;
        x = x * x % mod;
        n  = n >> 1;
    }
    return ans;
}

int gcd(int a, int b){
    if(a % b == 0) return b;
    else return (gcd(b, a%b));
}



int main(){
    string s;
    cin >> s;
    int len = s.length();
    ll num = 0;
    map<int, int> m;
    m[0]++;
    for(int i = 0; i < len; i++){
        num += (s[len - i - 1] - 48) * mpow(10, i, 2019);
        num %= 2019;
        m[num]++;
    }
    ll ans = 0;
    for(auto x: m){
        ans += (x.second * (x.second - 1)) / 2;
    }
    cout << ans << endl;
} 

Measured memory_bytes: 3772
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
As = nl()

max_diff = 0
for i in range(N-1):
    for j in range(i+1, N):
        diff = abs(As[i] - As[j])
        if diff > max_diff:
            max_diff = diff
print(max_diff)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

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

    vector<string> str(h);
    for (int i = 0; i < h;i++){
        cin >> str[i];
    }

    vector<stringstream> result(h);

    for (int now_i= 0; now_i < h; now_i++){
        for (int now_j = 0; now_j < w;now_j++){
            if(str[now_i][now_j]!='#'){
                int res = 0;
                for (int i = now_i - 1; i <= now_i + 1;i++){
                    for (int j = now_j - 1; j <= now_j + 1; j++){
                        if(i>=0&&j>=0){
                            if(i<h&&j<w){
                                if(str[i][j]=='#'){
                                    res++;
                                }
                            }
                        }
                    }
                }
                result[now_i] << res;
            }
            else{
                result[now_i] << str[now_i][now_j];
            }

        }
    }

    for (unsigned int i = 0; i < result.size();i++){
        cout << result[i].str() << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

vector<ll> enumDivisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i*i <= n; ++i) {
        if (n%i != 0) continue;
        res.push_back(i);
        if (i*i != n) res.push_back(n/i);
    }
    return res;
}

int main() {
    ll n;
    cin >> n;
    int ans = 0;
    for (ll x : enumDivisor(n)) {
        if (x == 1) continue;
        ll tmp = n;
        while (tmp %x == 0) tmp /= x;
        tmp %= x;
        if (tmp == 1) ++ans;
    }

    ans += enumDivisor(n-1).size() - 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,A[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47},B[20]={0},w=0,x=0,y=0,z=0;
    cin>>n;
    rep(i,15){
        int a=n;
        while(a>0) a=a/A[i],B[i]+=a;
    }
    rep(i,15) if(B[i]>=74) w++;
    rep(i,15)rep(j,15) if(B[i]>=2&&B[j]>=24&&i!=j) x++;
    rep(i,15)rep(j,15) if(B[i]>=4&&B[j]>=14&&i!=j) y++;
    rep(i,15)rep(j,15)rep(k,15) if(B[i]>=2&&B[j]>=4&&B[k]>=4&&i!=j&&j!=k&&k!=i) z++;
    cout<<w+x+y+z/2;
}

Measured memory_bytes: 256
# AOJ 0068 Enclose Pins with a Rubber Band
# Python3 2018.6.22 bal4u

def cross(a, b):
	return a.real*b.imag - a.imag*b.real
	
# 凸包　入力: 座標リスト　リターン:凸包を構成する座標リスト
def convex_hull(p):
	pp = sorted(p, key=lambda x:(x.imag,x.real))  # y座標を優先して昇順、同じならx座標で昇順
	n = len(pp)
	ans, j = [0]*(n+1), 0
	for i in range(n):
		while j > 1 and cross(ans[j-1]-ans[j-2], pp[i]-ans[j-1]) <= 0: j -= 1
		ans[j] = pp[i]
		j += 1
	k = j
	for i in range(n-2, -1, -1):
		while j > k and cross(ans[j-1]-ans[j-2], pp[i]-ans[j-1]) <= 0: j -= 1
		ans[j] = pp[i]
		j += 1
	return ans[0:j-1]
	
while 1:
	n = int(input())
	if n == 0: break
	p = []
	for i in range(n):
		x, y = list(map(float, input().split(',')))
		p.append(complex(x, y))
	print(n - len(convex_hull(p)))


Measured memory_bytes: 5632
(N, M, C) = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

a = []
N.times do
  a << gets.split.map(&:to_i)
end

result = 0

a.each do |data|
  p = 0
  data.each_with_index do |d, idx|
    p += d * B[idx]
  end
  if p + C > 0
    result += 1
  end
end

puts result

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

namespace PGC
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
			var Q = int.Parse(Console.ReadLine());
			var M = Console.ReadLine().Split().Select(int.Parse).ToArray();

			var ans = new HashSet<int>();
			for (int i = 0; i <= (1 << N); i++)
			{
				var val = 0;
				for (int j = 0; j < N; j++)
				{
					if ((i >> j) % 2 == 1)
					{
						val += A[j];
					}
				}
				ans.Add(val);
			}

			for (int i = 0; i < Q; i++)
			{
				var s = ans.Contains(M[i]) ? "yes" : "no";
				System.Console.WriteLine(s);
			}
		}
	}
}



Measured memory_bytes: 20572
#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; }

const int limit = 100005;
using edge = struct {int to; long long cost;};

int n;
vector<edge> tree[limit];
vector<long long> dist;

void dfs(int v, long long d = 0, int p = -1){
    dist[v] = d;
    for(auto &e : tree[v]) {
        if(e.to == p) continue;
        dfs(e.to, d + e.cost, v);
    }
}

vector<long long> calcDist(int s){
    dist = vector<long long>(n);
    dfs(s);
    return dist;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }
    int q, k;
    cin >> q >> k;
    --k;
    vector<ll> distK = calcDist(k);
    rep(i,q){
        int x, y;
        cin >> x >> y;
        --x; --y;
        ll ans = distK[x] + dist[y];
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long LL;
#define N 120000

int n,g[2],a[N][3],b[N],c[N],bit[2][N],f[2];

int qry(int k,int x){
	int ret=0;
	for (;x;x-=x&(-x)) ret+=bit[k][x];
	return ret;
}

void add(int k,int x){
	for (;x<=n;x+=x&(-x)) ++bit[k][x];
}

int main(){
	scanf("%d",&n);
	for (int i=0;i<3;++i)
		for (int j=1;j<=n;++j) scanf("%d",a[j]+i);
	for (int i=1;i<=n;++i){
		if (a[i][1]%3!=2){puts("No"); return 0;}
		if (a[i][0]==a[i][1]-1&&a[i][2]==a[i][1]+1){
			b[i]=a[i][2]/3; c[i]=0;
		}
		else{
			if (a[i][0]==a[i][1]+1&&a[i][2]==a[i][1]-1){
				b[i]=a[i][0]/3; c[i]=1;
			}
			else{puts("No"); return 0;}
		}
	}
	for (int i=1;i<=n;++i)
		if ((b[i]-i)%2!=0){puts("No"); return 0;}
		else{
			int x=(i-1)/2-qry(i%2,b[i]),y=(b[i]-i)/2;
			add(i%2,b[i]);
			f[i%2]^=x&1;
			g[i%2]^=c[i]^(y&1);
		}
	if (f[0]!=g[1]){puts("No"); return 0;}
	if (f[1]!=g[0]){puts("No"); return 0;}
	puts("Yes");
	
	return 0;
}
			

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

int main() {
    ll n;
    string s;
    cin >> n >> s;

    if(s.substr(0, n / 2) == s.substr(n / 2)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;

/////////////////////////////////////////////////////////

void Main(){
  int N; cin >> N;
  vector<int> X(N);
  rep(i, 0, N) cin >> X[i];
  vector<int> Y = X;
  sort(Y.begin(), Y.end());
  int mid1 = Y[N / 2 - 1], mid2 = Y[N / 2];
  rep(i, 0, N){
    if(X[i] <= mid1) out(mid2)
    else out(mid1)
  }
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int t_hp,t_atk,a_hp,a_atk;
    cin >> t_hp >> t_atk >> a_hp >> a_atk;
    bool is_t_tern = true;
    while (true) {
        if ((t_hp) <= 0 || (a_hp)<= 0) {
            cout << ((a_hp <= 0 )? "Yes" : "No") << endl;
            return;
        }
        ((is_t_tern) ? a_hp : t_hp) -= ((is_t_tern) ? t_atk : a_atk);
        is_t_tern = !is_t_tern;
    }
}

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


Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


public class Main {
	static int N;
	static int[][] S;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
			 N = sc.nextInt();

			 S = new int[N][2];
			 for(int i = 0 ; i < N ; i++){
				 for(int j = 0 ; j < 2 ; j++){
					 S[i][j] = sc.nextInt();
				 }
			 }
		sc.close();

	    Arrays.sort(S, new Comparator<int[]>() {
	        public int compare(int[] o1, int[] o2) {
	            //return o1[0] - o2[0];    //[0] をキーにソート(昇順)
	            return o2[0] - o1[0];    //[0] をキーにソート(降順)
	        }
	    });
/*
		 for(int i = 0 ; i < N ; i++){
			 for(int j = 0 ; j < 2 ; j++){
				 System.out.println(S[i][j]);
			 }
		 }
*/

	    long ans = S[0][0] + S[0][1];
	    System.out.println(ans);
	}
}

Measured memory_bytes: 94284
import java.util.*;

public class Main {

    private static int A;
    private static int B;
    private static int C;
    private static int D;
    private static int E;
    private static int F;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        D = sc.nextInt();
        E = sc.nextInt();
        F = sc.nextInt();
        System.out.println(solve());
    }

    private static String solve() {
        Result max = null;
        for (int water : availableWaters()) {
            int sugar = calcAvailableSugar(water);
            Result r = new Result(water, sugar);

            if( max == null || r.noudo() > max.noudo()) {
                max = r;
            }
        }
        return (max.water + max.sugar) + " " + max.sugar;
    }

    private static int calcAvailableSugar(int water) {
        // waterは100単位のはず
        int maxSugar = Math.min(F - water, water / 100 * E);

        int cm = maxSugar/C;
        int dm = maxSugar/D;
        int max = 0;
        for (int c = 0; c <= cm; c++) {
            for (int d = 0; d <= dm; d++) {
                int sugar = c*C + d*D;
                if( sugar <= maxSugar ) {
                    max = Math.max(max, sugar);
                }
            }
        }
        return max;
    }

    private static class Result {
        private final int water;
        private final int sugar;

        public Result(int water, int sugar) {
            this.water = water;
            this.sugar = sugar;
        }

        private double noudo() {
            return (double)sugar * 100 / (water + sugar);
        }
    }

    private static List<Integer> availableWaters() {
        Set<Integer> set = new HashSet<>();
        int am = F/(A*100);
        int bm = F/(B*100);
        for (int a = 0; a <= am; a++) {
            for (int b = 0; b <= bm; b++) {

                int water = a*A*100 + b*B*100;
                if( water < F ) {
                    set.add(water);
                }
            }
        }
        set.remove(0);

        List<Integer> list = new ArrayList<>(set);
        list.sort(Comparator.naturalOrder());
        return list;
    }
}


Measured memory_bytes: 22612
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def solve():
    n = getN()
    li = []
    for i in range(n):
        li.append(getN())

    last = dict()
    ans = [0 for i in range(n+1)]
    ans[0] = 1
    for i in range(1, n+1):
        tgt = li[i-1]
        if i >= 2 and tgt == li[i-2]:
            last[tgt] = i
            ans[i] = ans[i-1]
            continue
        if tgt not in last:
            ans[i] = ans[i-1]
            last[tgt] = i
        else:
            ans[i] = ans[i-1] + ans[last[tgt]]
            last[tgt] = i

    print(max(ans) % MOD)


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()


Measured memory_bytes: 807524
integer N
character(100000) S
integer CNT(26)
integer tmp
integer(16) ans
read*,N
read*,S

!実に読みづらい名前になってしまった
!各文字がどこにいられるかの場所
CNT=1
do i=1,N
  tmp=ichar(S(i:i))-ichar("a")+1
  CNT(tmp)=Cnt(tmp)+1
end do
ans=1
do i=1,26
  ans=mod(ans*cnt(i),10**9+7)
end do
ans=ans-1
print"(i0)",ans
end

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  int K = nextLong();
  vector<ll> a(N);
  REP(i, N) a[i] = nextLong();
  for (int i = K; i < N; i++) {
    if (a[i - K] < a[i]) cout << "Yes" << '\n';
    else cout << "No" << '\n';
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 4860
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
ll keta(ll num){ ll k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll n, k;
    ll a[100010];

    cin >> n >> k;

    rep(i, n){
        cin >> a[i];
    }

    ll x = 0;
    repr(j, 50, 0){
        ll sum = 0;
        rep(i, n){
            if(a[i] & (1LL<<j)) sum++;
        }
        if(sum*2 < n) x |= (1LL<<j);
        if(x > k) x &= ~(1LL<<j);
    }

    ll res = 0;
    rep(i, n){
        res += x^a[i];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int a[110];
int main()
{
   int n,ans=0;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
   	cin>>a[i];
   }
   for(int i=1;i<=n;i++)
   {
   	if(i%2==1&&a[i]%2==1)
   	ans++;
   }
   cout<<ans;
   return 0;
}


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

int dp[3][110]={};
//dp[i][j]:(i,j)までの点で得ることのできるアメの最大値

int main(){
    int N;
    cin>>N;
    
    int field[3][110];
    
    for(int i=1; i<=2; i++){
        for(int j=1; j<=N; j++)cin>>field[i][j];
    }
    
    dp[1][0]=0;//dp初期条件
    dp[2][0]=0;
    for(int i=1; i<=2; i++){
        for(int j=0; j<N; j++){
            //dp漸化式
            //dp[i][j+1]=max(dp[i][j],dp[i-1][j+1])+field[i][j+1](i==2)
            //dp[i][j+1]=dp[i][j]+field[i][j+1](i==1)
            if(i==1)
                dp[i][j+1]=dp[i][j]+field[i][j+1];
            else
                dp[i][j+1]=max(dp[i][j],dp[i-1][j+1])+field[i][j+1];
        }
    }
    
    cout<<dp[2][N]<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
  size_t N;
  int A, B;
  scanf("%llu %d %d", &N, &A, &B);

  int res=0;
  for (size_t i=0; i<N; ++i) {
    int t;
    scanf("%d", &t);
    if (!(A<=t && t<B)) ++res;
  }
  printf("%d\n", res);
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
int n;
ll x,ans,minn[2020][2020];
int main()
{
	scanf("%d%lld",&n,&x);
	for (int i=1;i<=n;++i)
		scanf("%lld",&minn[i][0]),ans+=minn[i][0];
	for (int i=1;i<n;++i)
	{
		minn[1][i]=min(minn[1][0],minn[n][i-1]);
		for (int j=2;j<=n;++j)
			minn[j][i]=min(minn[j][0],minn[j-1][i-1]);
	}
	for (int i=0;i<n;++i)
	{
		ll now=x*i;
		for (int j=1;j<=n;++j)
			now+=minn[j][i];
		ans=min(ans,now);
//		printf("%d %lld\n",i,now);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 31872
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<vector<int> > G(n);
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  
  vector<int> mx(n,0);
  function<void(int, int, int)> dfs1=
    [&](int v,int p,int d){
      chmax(mx[v],d);
      for(int u:G[v]){
        if(u==p) continue;
        dfs1(u,v,max(v,mx[v]));
      }      
    };
  dfs1(0,-1,0);
  
  vector<map<int, int> > dp(n);
  function<int(int, int, int)> dfs4=
    [&](int v,int p,int d){
      if(dp[v].count(d)) return dp[v][d];
      int &res=dp[v][d];
      res=0;
      for(int u:G[v]){
        if(u==p||u>d) continue;
        res+=1+dfs4(u,v,d);
      }
      return res;
    };
  
  vector<int> ans(n,0);
  function<void(int, int)> dfs2=
    [&](int v,int p){      
      for(int u:G[v]){
        if(u==p) continue;
        dfs2(u,v);
      }
      if(p<0) return;
      ans[v]=1+dfs4(v,p,mx[v]);
      if(v<mx[p]) ans[v]-=1+dfs4(v,p,mx[p]);
    };
  dfs2(0,-1);
  
  function<void(int, int)> dfs3=
    [&](int v,int p){
      for(int u:G[v]){
        if(u==p) continue;
        ans[u]+=ans[v];
        dfs3(u,v);
      }
    };
  dfs3(0,-1);

  for(int i=1;i<n;i++){
    if(i>1) cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}


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

int main() {
  int h, n;
  cin >> h >> n;
  vi a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  vi dp(h + 1, 1e8);
  dp[0] = 0;
  rep(i, n) rep(j, h + 1) {
    int nj = min(h, j + a[i]);
    dp[nj] = min(dp[nj], dp[j] + b[i]);
  }
  cout << dp[h] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define TRACE(x) cerr << #x << " = " << x << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define SZ(x) (int)(x).size()
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
template<class Num>
Num mabs(Num A){
  if(A < 0) return -A;
  return A;
}

const int N = 2005, mod = 1e9 + 7;

inline int add(int a, int b){
  int ret = a + b;
  if(ret >= mod) ret -= mod;
  return ret;
}

inline int sub(int a, int b){
  int ret = a - b;
  if(ret < 0) ret += mod;
  return ret;
}

int a, b, c, d;
set<ll> S;

int main(){
  scanf("%d %d %d %d", &a, &b, &c, &d);
  
  S.insert((ll)a * c);
  S.insert((ll)a * d);
  S.insert((ll)b * c);
  S.insert((ll)b * d);
  
  printf("%lld\n", *S.rbegin());
  
  return 0;
}


Measured memory_bytes: 3832
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int from,to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
edge G[2010];
int d[2010];
bool negative[2010];

int Bellman_Ford(int s){
	for(int i=0;i<N;i++){
		d[i]=INF;
	}
	d[s]=0;
	for(int j=0;j<N;j++){
		bool update=false;
		for(int i=0;i<M;i++){
			edge e=G[i];
			if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
		}
		if(!update){
			break;
		}
	}
}

void FN(){
	fill(d,d+N,0);
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			edge e=G[j];
			if(d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				if(i==N-1){
					negative[e.to]=true;
				}
			}
		}
	}
}

signed main(){
	cin>>N>>M;
	REP(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		G[i].from=a-1;
		G[i].to=b-1;
		G[i].cost=-c;
	}
	FN();
	DEB(negative[0])END
	if(negative[N-1]==true){
		cout<<"inf"<<endl;
	}
	else{
		Bellman_Ford(0);
		cout<<-d[N-1]<<endl;
	}
	return 0;
}



Measured memory_bytes: 256