akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Maybe
import Data.Ord
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  s <- getLine
  let t = take 4 s ++ " " ++ drop 4 s
  putStrLn t

 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define txt freopen("ip.txt", "r", stdin); freopen("op.txt", "w", stdout)
#define a3 INT_MAX
#define i3 INT_MIN
#define a6 INT64_MAX
#define i6 INT64_MIN
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define div2(a) (!(a&1))
#define deb(x) cout<<(#x)<<" "<<(x)<<"\n";
#define newl cout<<"\n" 
#define all(s) s.begin(),s.end()
#define pi 3.14159265358979323846
#define fp(x) fixed<<setprecision(x)<<
template<class T>
T mod(T a){
    if(a < 0){
        a += 1000000007;
    }
    return a%1000000007; 
}
template<class T>
T addmod(T a, T b){
    return (mod(a) + mod(b)) % 1000000007;
}
template<class T>
T prodmod(T a, T b){
    return (mod(a) * mod(b)) % 1000000007;
}
template<class T>
T bin_exp(T a, T b)
{
    T res = 1;
    T temp = 1;
    if (b <= 1)
        return a;
    if (b %2 == 0)
        res = bin_exp(a * a, b / 2);
    else
    {
        res *= a;
        temp = bin_exp(a, --b);
    }
    return res * temp;
}
template<class T>
T bin_expmod(T a, T b)
{
    T res = 1;
    T temp = 1;
    if (b <= 1)
        return a;
    if (b %2 == 0)
        res = bin_expmod(prodmod(a,a), b / 2);
    else
    {
        res = prodmod(a,res);
        temp = bin_exp(a, --b);
    }
    return prodmod(res , temp);
}

template<class T>
int digit(T a)
{
    vector<long long> dig = {
        0,
        9,
        99,
        999,
        9999,
        99999,
        999999,
        9999999,
        99999999,
        999999999,
        9999999999,
        99999999999,
        999999999999,
        9999999999999,
        99999999999999,
        999999999999999,
        9999999999999999,
        99999999999999999,
        999999999999999999,
        INT64_MAX};
    auto it = lower_bound(dig.begin(), dig.end(), a);
    int idx = (it - dig.begin());
    return idx;
}
template<class T>
int sumAllInts(T n){
    int a = 1;
    int su = 0;
    while(n){
        su += n%10;
        n/=10;
    }
    return su;
}
template<class T>
void split(char c,T s){
    int n = s.size();
    int i = 0;
    while ((cout<<s[i],i+=1) && (i<n) && (cout<<c<<' '));
}

void solve(){
  long long int N,T;
  cin>>N>>T;
  vector<int> A(N);
  for(unsigned int i=0;i<A.size();i++) cin>>A[i];
  long long int total=T;
  for(unsigned int i=1;i<A.size();i++)
  {
      if(A[i]-A[i-1]>T)
      total+=T;
      else
      {
          total+=(A[i]-A[i-1]);
      }
      
  }
  cout<<total;
}
int main(){
    quickie;
    //txt;
    int t=1;
    while(t--){
        solve(); 
        newl; 
    } 
    return 0;
}

Measured memory_bytes: 3896
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int n;
  while(cin >> n, n){
    int id, cnt = 0;
    ll a, num, sum[5000];
    fill(sum, sum+5000, 0);
    vector<int> in;
    for(int i = 0; i < n ; i++){
      cin >> id >> a >> num;
      if(sum[id] <= 1000000)
	sum[id] += a*num;
      if(find(in.begin(), in.end(),id)==in.end()){
	in.push_back(id);
      }
    }

    for(int i = 0; i < in.size(); i++){
      if(sum[in[i]] >= 1000000){
	cnt++;
	cout << in[i] << endl;
      }
    }
    if(!cnt) cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1272
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int h = saori.saori_hayami();
		int w = saori.saori_hayami();
		int n = saori.saori_hayami();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			x[i] = saori.saori_hayami();
			y[i] = saori.saori_hayami();
			a[i] = saori.saori_hayami();
		}
		int hh = 0;
		int ww = 0;
		for(int i = 0;i < n;i++){
			if(a[i] == 1){
				if(hh < x[i]){
					hh = x[i];
				}
			} else if(a[i] == 2){
				if(h > x[i]){
					h = x[i];
				}
			} else if(a[i] == 3){
				if(ww < y[i]){
					ww = y[i];
				}
			} else if(a[i] == 4){
				if(w > y[i]){
					w = y[i];
				}
			}
		}
		int numw = w-ww;
		if(numw < 0){
			numw = 0;
		}
		int numh = h-hh;
		if(numh < 0){
			numh = 0;
		}
		System.out.println(numh*numw);

		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(char c='a';c<='z';c++){
    bool found =false;
    for(int i=0;i<s.length();i++){
      if(s.at(i)==c){
        found=true;
      }
    }
      if(!found){
        cout<<c<<endl;
        return 0;
      }
    }
    cout<<"None"<<endl;
    return 0;
}

Measured memory_bytes: 512
import fractions

n,m = map(int, input().split( ))
a = list(map(int, input().split( )))
for i in range(n):
    a[i]//=2

pow2 = 2**50 #10**9 <= 2**30

p2 = set()

for i in range(n):
    tmp = fractions.gcd(pow2,a[i])
    p2.add(tmp)
    if len(p2)>1:###
        print(0)
        exit()
def lcd(x,y):
    tmp = fractions.gcd(x,y)
    x//=tmp 
    y//=tmp 
    return x*y*tmp
tmp = a[0]

for i in range(n):
    tmp = lcd(tmp,a[i])
    if tmp > m:
        print(0)
        exit()

tmp2 = tmp*2

ans = m//tmp 
ans2 = m//tmp2
ans -= ans2
print(ans)


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

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

    int t = 1;
    while(N--) {
        t = min(t + K, t * 2);
    }
    cout << t << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

void trace(int A[],int N){
  int i;
  for (i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int i;
  int v;
  int j;
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
      A[j+1]=v;
      trace(A,N);
  }
}
    

int main(){
  int N,i,j;
  int A[1000];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  insertionSort(A,N);

  return 0;
}
  



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

using namespace std;

typedef long long ll;

int main()
{
    ll R, C, Q;
    while (cin >> R >> C >> Q, R) {
        vector<ll> a(Q), b(Q), order(Q);
        for (int i = 0; i < Q; i++) {
            cin >> a[i] >> b[i] >> order[i];
        }
        vector<bool> used_a(R, 0), used_b(C, 0);
        ll r = 0, c = 0, res = 0;
        for (int i = Q-1; i >= 0; i--) {
            if (a[i] == 0) { // ティツ。ツ?
                if (!used_a[b[i]]) {
                    used_a[b[i]] = 1;
                    r++;
                    if (order[i] == 1) {
                        res += C - c;
                    }
                }
            } else {         // テ・ツ按?
                if (!used_b[b[i]]) {
                    used_b[b[i]] = 1;
                    c++;
                    if (order[i] == 1) {
                        res += R - r;
                    }
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 2368
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}



int main(){
  int n,k;
  cin>>n>>k;
  int x[n];
  for(int i = 0; i < n; i++){
    cin>>x[i];
  }
  
  int ans = 1000000000;
  
  
  for(int i = 0; i < n-k+1; i++){
     int l = x[i];
     int r = x[i+k-1];
     ans = min(abs(l)+abs(r-l),ans);
     ans = min(abs(r)+abs(l-r),ans);
     }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

void change(int num[], int x, int y){
        int g;

        g = num[y-1];
        num[y-1] = num[x-1];
        num[x-1] = g;
}

int main(){
        int num[30];
        int w,n;
        int a,b;
        char g;
        int i;

        scanf("%d",&w);
        for(i = 0; i < w; i++){
                num[i] = i + 1;
        }
        scanf("%d",&n);
        for(i = 0; i < n; i++){
                scanf("%d %c %d",&a, &g, &b);
                change(num, a, b);
        }

        for(i = 0; i < w; i++)
                printf("%d\n",num[i]);

        return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int  ll;
#define pb push_back
#define mp make_pair
#define N 200005


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

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

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int n,q,i,j,cnt=0;

  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  int B[q];
  for(i=0;i<q;i++){
    scanf("%d",&B[i]);
  }
  
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(B[i]==A[j]){
	cnt++;
	break;
      }
    }
  }

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

  return 0;
  
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int main() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    int a, b;
    cin >> a >> b;
    puts(a < b ? "0" : "10");
    return 0;
}


Measured memory_bytes: 256
#[test]
fn test_solve() {
    assert_eq!(solve("3 3\n.#.\n..#\n#..\n"), "10\n");
    assert_eq!(solve("2 4\n....\n....\n"), "0\n");
    assert_eq!(solve("4 3\n###\n###\n...\n###\n"), "6\n");
    assert_eq!(solve("3 3 ### ### ###"), "0\n");
    assert_eq!(solve("3 3 #.# .#. #.#"), "20\n");
    assert_eq!(solve("3 3 ### #.# ###"), "4\n");
}
fn solve(s: &str) -> String {
    let mut sc = Scanner::from_str(s);

    let h: usize = sc.read();
    let w: usize = sc.read();
    let g: Vec<Vec<_>> = (0..h).map(|_| sc.get().chars().collect()).collect();

    let mut seen = vec![vec![false; w]; h];
    let mut ret: u64 = 0;
    for i in 0..h {
        for j in 0..w {
            if !seen[i][j] {
                seen[i][j] = true;
                let mut sa = 0;
                let mut sb = 0;
                let mut q = vec![(i, j)];
                while let Some((i, j)) = q.pop() {
                    let c = g[i][j];
                    if c == '#' {
                        sa += 1;
                    } else {
                        sb += 1;
                    }
                    let mut chk = |i: usize, j: usize| {
                        if !seen[i][j] && g[i][j] != c {
                            seen[i][j] = true;
                            q.push((i, j))
                        }
                    };
                    if i > 0 {
                        chk(i - 1, j)
                    }
                    if i < h - 1 {
                        chk(i + 1, j)
                    }
                    if j > 0 {
                        chk(i, j - 1)
                    }
                    if j < w - 1 {
                        chk(i, j + 1)
                    }
                }
                ret += sa * sb;
            }
        }
    }
    format!("{}\n", ret)
}

fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int A[n], B[n - 1];
	for (int i = 0; i < n - 1; i++)
		cin >> B[i];
	A[0] = B[0];
	A[n - 1] = B[n - 2];
	for (int i = 1; i < n - 1; i++){
		A[i] = min(B[i - 1], B[i]);
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans += A[i];
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    int q;
    cin>>q;
    vi v;
    rep(i,q){
        int a,x;
        cin>>a;
        if(a==0)cin>>x,v.pb(x);
        else if(a==1)cin>>x,fin(v[x]);
        else v.pop_back();
    }
}




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

vector<bool> seen;

ll dfs(ll prev, ll now, vector<vector<ll>>& adj, vector<ll>& dp) {
	if (dp[now] > 0) return dp[now];
	if (seen[now]) {
		seen[now] = false;
		return -1;
	}
	seen[now] = true;
	ll ret = 0;
	for (auto i : adj[now]) {
		if (i == prev) continue;
		ll x = dfs(now, i, adj, dp);
		if (x == -1) {
			seen[now] = false;
			return -1;
		}
		ret = max(ret, x);
	}
	seen[now] = false;
	return dp[now] = ret + 1;
}

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

	auto idx = [&] (ll i, ll j) {
		if (i > j) swap(i, j);
		ll ret = n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2;
		return ret + j - i - 1;
	}; // {i, j} が対戦する試合の頂点番号

	ll m = n * (n - 1) / 2;
	vector<vector<ll>> adj(m);
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n - 2; j++) {
			ll u = idx(i, a[i][j]), v = idx(i, a[i][j + 1]);
			adj[u].push_back(v);
		}
	}

	vector<ll> dp(m, 0);
	ll ans = 0;
	seen.resize(m, false);
	for (ll i = 0; i < m; i++) {
		ll x = dfs(-1, i, adj, dp);
		if (x == -1) {
			cout << -1 << endl;
			return 0;
		} else ans = max(ans, x);
	}

	cout << ans << endl;
}

Measured memory_bytes: 42396
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ( abs(c - a) <= d || (abs(b - a) <= d && abs(c - b) <= d)) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int w = sc.nextInt();
            int h = sc.nextInt();
            if (w == 0 && h == 0) {
                break;
            }
            char[][] field = new char[h][];
            for (int i = 0; i < h; i++) {
                field[i] = sc.next().toCharArray();
            }
            HashMap<Character, Boolean> counts = new HashMap<>();
            int whiteCount = 0;
            int blackCount = 0;
            char current = (char)('W' + 1);
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (field[i][j] == '.') {
                        Result result = new Result();
                        check(i, j, current, field, result);
                        if (result.white && !result.black) {
                            counts.put(current, true);
                        } else if (!result.white && result.black) {
                            counts.put(current, false);
                        }
                        current = (char)(current + 1);
                    }
                }
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (counts.containsKey(field[i][j])) {
                        if (counts.get(field[i][j])) {
                            whiteCount++;
                        } else {
                            blackCount++;
                        }
                    }
                }
            }
            sb.append(blackCount).append(" ").append(whiteCount).append("\n");
        }
        System.out.print(sb);
    }
    
    static void check(int r, int c, char mark, char[][] field, Result result) {
        if (field[r][c] == 'W') {
            result.white = true;
            return;
        }
        if (field[r][c] == 'B') {
            result.black = true;
            return;
        }
        if (field[r][c] != '.') {
            return;
        }
        field[r][c] = mark;
        if (r != 0) {
            check(r - 1, c, mark, field, result);
        }
        if (r < field.length - 1) {
            check(r + 1, c, mark, field, result);
        }
        if (c > 0) {
            check(r, c - 1, mark, field, result);
        }
        if (c < field[r].length - 1) {
            check(r, c + 1, mark, field, result);
        }
    }
    
    static class Result {
        boolean white = false;
        boolean black = false;
    }
}


Measured memory_bytes: 35412
#include <iostream>
#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>;

int main()
{
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k)
    {
        cout << s << endl;
    }
    else
    {
        string ans = s.substr(0, k);
        cout << ans + "..." << endl;
    }
}

Measured memory_bytes: 3628
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


N = int(input())
x, y = [], []
for i in range(N):
    a, b = map(int, input().split())
    x.append([a, i])
    y.append([b, i])
x.sort()
y.sort()

e = []
for i in range(N-1):
    e.append([abs(x[i][0]-x[i+1][0]), x[i][1], x[i+1][1]])
    e.append([abs(y[i][0]-y[i+1][0]), y[i][1], y[i+1][1]])

e.sort()

uft = UnionFind(N)

ans = 0
for w, s, t in e:
    if not uft.same(s, t):
        uft.union(s, t)
        ans += w

print(ans)


Measured memory_bytes: 62712
#include <iostream>

using namespace std;

bool judge(string s) {
  int unitLen = s.size() / 2;
  if (s.size() - unitLen * 2)return false;
  for (int i = 0; i < unitLen; ++i)
    if (s[i] != s[i + unitLen]) return false;
  return true;
}

int main() {
  string s;
  cin >> s;
  for (int i = s.size() - 1; i >= 0; --i) {
    if (judge(s.substr(0, i))) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#define ll long long
#define ull unsigned long long
#define scf1(a)  scanf("%lld",&a)
#define scf2(a,b)  scanf("%lld %lld",&a,&b)
#define pf    printf
#define pb    push_back
#define rsrt(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define ff first
#define ss second
#define spd ios_base::sync_with_stdio(false)
#include<bits/stdc++.h>
using namespace std;
ll N=1e5;
int main()
{
    spd;
    char c,a;
    cin>>c;
    a = ++c;
    cout<<a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    ll x, t;
    cin >> x >> t;
    cout << max(x-t, 0ll) << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0, i_length = (n); i < i_length; i++)
#define MOD 1000000007
#define ll long long

int main() {
	int n;
	cin >> n;
	vector<ll> a, b, c;
	rep(i, n) {
		ll x;
		cin >> x;
		a.push_back(x);
		b.push_back(a[i] - i);
		c.push_back(-a[i] - i);
	}

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

	ll ans = 0;

	rep(i, n) {
		ans += upper_bound(c.begin(), c.end(), b[i]) - lower_bound(c.begin(), c.end(), b[i]);
	}

	cout << ans << endl;

	return 0;

}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int x;
    cin >> x;
    if(x == 3 || x == 5 || x == 7){
        print("YES");
        return 0;
    }

    print("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int X, Y, Z;

int main(void){
	//IO("test.in", "test.out");
	scanf("%d%d%d", &X, &Y, &Z);
	printf("%d\n", (X - Z) / (Y + Z));
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <tuple>

using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

void solve(){
  int r, d, x;
  cin >> r >> d >> x;
  rep(i,10){
     x = r*x-d;
    cout << x << endl;
  }
}

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


Measured memory_bytes: 256
while 1:
    H,W=map(int,input().split())
    if W==0 and H==0:
        break
    else:
        print("#"*W)
        for char in range(H-2):
            print("#",end="")
            print("."*(W-2),end="")
            print("#")
        print("#"*W)
    print()   


Measured memory_bytes: 5636
n,m,x=map(int,input().split())
B=[]
for i in range(n):
    B.append(list(map(int,input().split())))
    
ans=10**9
for i in range(2**n):
    A=[0]*m
    cnt=0
    for j in range(n):
        if i>>j&1:
            cnt+=B[j][0]
            for k in range(m):
                A[k]+=B[j][k+1]
    if min(A)>=x:
        ans=min(cnt,ans)
if ans==10**9:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9224
#define _GLIBCXX_DEBUG
#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;
    int s = stoi(S);
    int A = (s / 1000) % 10, B = (s / 100) % 10, C = (s / 10) % 10, D = s % 10;
    vector<int> X(4);
    X[0] = A; X[1] = B; X[2] = C; X[3] = D;
    int sum;
    for(int bit = 0; bit < (1 << 3); bit++) {
        sum = X[0];
        bitset<3> b(bit);
        for(int i = 0; i < 3; i++) {
            if(b.test(i)) sum += X[i + 1];
            else sum -= X[i + 1];
        }
        if(sum == 7) {
            for(int i = 0; i < 4; i++) {
                if(i == 0) {
                    cout << X[0];
                    if(b.test(i)) cout << '+';
                    else cout << '-';
                }
                else if(i != 3) {
                    cout << X[i];
                    if(b.test(i)) cout << '+';
                    else cout << '-';
                }
                else cout << X[3] << '=' << 7 << endl;
            }
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
//#include <stdio.h>
using namespace std;

int main(){
	int H, W;
	char c;
	while(1){
		cin >> H >> W;
		if (H == 0 && W ==0)  break;
		for (int i=0;i < H;i++){
			if (i % 2) c = '.';
			else c = '#';
			for (int j=0; j<W; j++){
				cout << c;
				if ( c == '#') c = '.';
				else c = '#';
				
			}
			cout << endl ;
		}
		cout << endl ;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main (void) {
  int n = 0;
  scanf("%d", &n);
  int arr[n];
  int sum = 0;

  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      sum = sum + arr[i] * arr[j];
    }
  }

  printf("%d", sum);
}


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

using namespace std;

int main()
{
    int N;
    while (cin >> N, N) {
        int a, sum = 0;
        for (int i = 0; i < N/4; i++) {
            cin >> a;
            sum += a;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3076
######### D 
from collections import deque
H, W = map(int, input().split())
Ch, Cw = map(lambda x:int(x)-1, input().split())
Dh, Dw = map(lambda x:int(x)-1, input().split())
meiro = []
for i in range(H):
    meiro.append(list(map(str, input())))
    
walk = [(0,1),(1,0),(0,-1),(-1,0)]
warp = [(i,j) for i in range(-2,3) for j in range(-2,3) if (i,j) not in [(0,0)]+walk]

q = deque()
q.append((Ch,Cw))
num = 0
meiro[Ch][Cw] = num


while q != deque():
#for _ in range(10):
    ph, pw = q.popleft()
    
    if meiro[ph][pw] != num:
        num += 1
    
    for h, w in walk:
        th = ph+h
        tw = pw+w
        
        if 0 <= th < H and 0 <= tw < W and meiro[th][tw] != '#' and meiro[th][tw] != meiro[ph][pw]:
            meiro[th][tw] = meiro[ph][pw]
            q.appendleft((th,tw))
    
    for h, w in warp:
        th = ph+h
        tw = pw+w
        
        if 0 <= th < H and 0 <= tw < W and meiro[th][tw] == '.':
            meiro[th][tw] = meiro[ph][pw] + 1
            q.append((th,tw))
    
if meiro[Dh][Dw] == '.':
    print(-1)
else:
    print(meiro[Dh][Dw])

Measured memory_bytes: 167532
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  int ct = 0;
  rep(i,n){
    if(h[i] >= k){
      ct++;
    }
  }
  cout << ct << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N, n, M, m, X, Y;
		int xmax = -101, ymin = 101;
		N = scanner.nextInt();
		M = scanner.nextInt();
		X = scanner.nextInt();
		Y = scanner.nextInt();

		for (n = 0; n < N; n++) {
			int num = scanner.nextInt();
			xmax = Math.max(xmax, num);
		}
		for (m = 0; m < M; m++) {
			int num = scanner.nextInt();
			ymin = Math.min(ymin, num);
		}
		
		scanner.close();
		
		if (ymin <= xmax) {
			System.out.println("War");
			return;
		}
		if (ymin <= X) {
			System.out.println("War");
			return;
		}
		if (xmax >= Y) {
			System.out.println("War");
			return;
		}
		
			System.out.println("No War");
	}
}


Measured memory_bytes: 23380
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
gcd = math.gcd
a,b,c,d = ma()
a1 = a*c
a2 = a*d
a3 = b*c
a4 = b*d
print(max(a1,a2,a3,a4))


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

int main() {
    int H, W;
    while(1) {
        
        cin >> H >> W;
        
        if(H == 0 && W == 0) {
            break;
        }
        
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                cout << '#';
            }
            cout << endl;
        }
        
        cout << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3100
#include<cstdio>
#include<cmath>
using namespace std;
int spfa(int x)
{
    int s=0;
    while(x){s++;x/=10;}
    return s;
}
int main()
{
    int a,b,c;long long s;
    scanf("%d%d",&a,&b);
    s=a*pow(10,spfa(b))+b;
    c=sqrt(s);
    if(c*c==s)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
#define ll long long
ll n;
ll gg;
ll a=100;
ll num;
int main(){
	cin>>n;
	num=0;
	gg=100;
	while(gg<n){
		gg+=gg/100;
		num++;
	}
	cout<<num<<endl;
	return 0;
} 

Measured memory_bytes: 3660
// abc053d: Card Eater
#include <stdio.h>
#include <stdlib.h>

#define upto(i,s,e,d) for(int i=(s);i<=(e);i+=(d))
#define downto(i,s,e,d) for(int i=(s);i>=(e);i-=(d))
#define in(n) scanf("%d",n)
#define out(d) printf("%d\n",d)

#define MAX 100000
int d[MAX+1];

int desc(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
}

int main(){
  int n;in(&n);
  int dn=1, setnum = 0;
  upto(i,0,n-1,1){
    int a;in(&a);
    if(d[a]==0) setnum++;
    if(dn<a) dn=a;
    d[a]++;
  }

  qsort(d+1,dn,sizeof(int),desc);

  upto(i,1,setnum,1){
    if(d[i]>2){
      int t = (d[i]-1)/2;
      n -= t*2;
      d[i] -= t*2;
    }
    if(d[i]==2){
      n-=2;
      if(i==setnum) d[i] -= 2;
      else{
        d[i]--;
        d[i+1]--;
      }
    }
  }
  out(n);

  return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;

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

	vector<vector<int>> dp(h+1, vector<int>(w)); 

    dp[0][0] = 1;
	rep(i, h) {
		rep(j, w) {
			for (int k = 0; k < (1 << (w-1)); k++) {
				// 2 つの横線がつながっているか調べる
				int ok = 1;
				rep(l, w-2) {
					if ( ((k >> l) & 1) && ((k >> (l+1)) & 1) ) {
						ok = 0;
					}
				}

				if(ok) {
					if(j >= 1 && ((k >> (j-1)) & 1)) {
						// 左方向に横線をたどるケース
						dp[i+1][j-1] += dp[i][j];
						dp[i+1][j-1] %= mod;
					}
					else if(j <= w-2 && ((k >> j) & 1)) {
						// 右方向に横線をたどるケース
						dp[i+1][j+1] += dp[i][j];
						dp[i+1][j+1] %= mod;
					}
					else {
						// 横線をたどらないケース
						dp[i+1][j] += dp[i][j];
						dp[i+1][j] %= mod;
					}
				}
			}
		}
	}

	cout << dp[h][K-1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <utility>
using namespace std;

int main() {
  string S; cin >> S;
  int c = 0;
  for (int i = 0; i < 4; i++) {
    if (S[i] == '+')
      c++;
    else
      c--;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#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>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
//#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    int a,b;
    cin>>a>>b;
    cout<<a*b-(a+b-1)<<endl;

}



    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main(){
    long long n,m,K;
    cin >> n >> m >> K;
    vector<long long>a(n),b(m);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<m;i++){
        cin >> b[i];
    }
    vector<long long>sum_a(n+1,0),sum_b(m+1,0);
    for(int i=0;i<n;i++){
        sum_a[i+1]+=sum_a[i]+a[i];
    }
    for(int i=0;i<m;i++){
        sum_b[i+1]+=sum_b[i]+b[i];
    }
    long long ans=0;
    for(int i=0;i<n+1;i++){
        if(K<sum_a[i])break;
        long long x=K-sum_a[i];
        long long y=upper_bound(sum_b.begin(),sum_b.end(),x)-(sum_b.begin())-1;
        ans=max(ans,y+i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9564
#include <stdio.h>

int main(){
  int x,y;
  int in,sec = 0,min = 0;
  int i;

  for(i = 0;i < 4;i++){
    in = 0;
    scanf("%d",&in);
    while(in >= 60){
      in -= 60;
      min++;
    }
    sec += in;
  }

  while(sec >= 60){
    sec -=60;
    min++;
  }
    

  printf("%d\n%d\n",min,sec);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

int N, M, L;

struct Edge {
	int to, cost, enemy;
	Edge(int _t, int _c, int _e) : to(_t), cost(_c), enemy(_e) {}
};
bool operator > (const Edge& e1, const Edge& e2) {
	if (e1.enemy < e2.enemy) return true;
	else if (e1.to > e2.to) return true;
	return e1.cost < e2.cost;
}
bool operator == (const Edge& e1, const Edge& e2) {
	if (e1.enemy == e2.enemy && e1.to==e2.to && e1.cost == e2.cost) return true;
	return false;
}
bool operator != (const Edge& e1, const Edge& e2) { return !(e1 == e2); }
bool operator < (const Edge& e1, const Edge& e2) { return !(e1 > e2) && (e1 != e2); }
bool operator >= (const Edge& e1, const Edge& e2) { return (e1 > e2) && (e1 == e2); }
bool operator <= (const Edge& e1, const Edge& e2) { return (e1 < e2) && (e1 == e2); }

const int INF = 1e9;
int d[110][110];

int main() {
	while (1) {
		cin >> N >> M >> L; if (N==0 && M==0 && L==0) break;
		vector< vector<Edge> > G(N+1, vector<Edge>());
		
		for (int i=0; i<M; i++) {
			int a, b, d, e; cin >> a >> b >> d >> e;
			G[a].push_back(Edge(b, d, e));
			G[b].push_back(Edge(a, d, e));
		}
		
		for (int i=0; i<=N; i++) fill(d[i], d[i] + L + 1, INF);
		
		d[1][0] = 0;
		
		priority_queue<Edge, vector<Edge>, greater<Edge> > q;
		q.push( Edge(1, 0, 0) );
		
		while (!q.empty()) {
			Edge e = q.top(); q.pop();
			
			for (int i=0; i<(int)G[e.to].size(); i++) {
				Edge ne = G[e.to][i];
				
				if (e.cost + ne.cost <= L) {
					if (d[ne.to][e.cost + ne.cost] > e.enemy) {
						d[ne.to][e.cost + ne.cost] = e.enemy;
						q.push(Edge(ne.to, e.cost + ne.cost, e.enemy));
					}
				}
				
				if (d[ne.to][e.cost] > e.enemy + ne.enemy) {
					d[ne.to][e.cost] = e.enemy + ne.enemy;
					q.push(Edge(ne.to, e.cost, e.enemy + ne.enemy));
				}
			}
		}
		
		int ans = INF;
		for (int i=0; i<=L; i++) ans = min(ans, d[N][i]);
		cout << ans << endl;
	}
	
	return 0;
}

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

using namespace std;
 
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
 
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
 
#define pint(x) printf("%d",x)
#define plint(x) printf("%lld",x)
#define endl '\n'
#define nl printf("\n");
#define ps printf(" "); 
 
#define all(x) x.begin(),x.end()
#define pb push_back
#define Set(a, s) memset(a, s, sizeof (a))
#define mod1 (lli)(1e9 + 7)
#define mod2 (lli)(1e9 + 9)
#define EPS 1e-9

#define fore(i,n) for(int i=n; i>=0; i--)
#define fors(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<lli> vli;
 
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
 
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
float roundoff(float val, float p){ return floor(val*pow(10.0,p)+0.5)/pow(10.0,p);}
lli power(lli a, lli b, lli mod){lli x=1,y=a; while(b > 0){if(b&1){x=(x*y)%mod;}y = (y*y)%mod; b /= 2;}return x;}
 
const int INF = 0x3f3f3f3f;
const float pi = 3.14159265;
 
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1};
 
int main(void) {
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    cout.tie(NULL);
	//srand (time(NULL));
	/*
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	*/
    // cout<<"Execution time : "<<tick()<<"\n";
    
	int n;
	int1(n);
	
	fors(i,0,n){
		int temp;
		int1(temp);
		if(temp%2==1){
			cout<<"first";
			exit(0);
		}
	}
	cout<<"second";
    return 0;
}


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


int main() {
  int H, W; cin >> H >> W;
  vector<vector<char>> s(H, vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> s[i][j];
    }
  }

//４隅
  if(s[0][0] == '#' && s[0][1] != '#' && s[1][0] != '#'){
    cout << "No" << endl;
    return 0;
  }

  if(s[0][W-1] == '#' && s[0][W-2] != '#' && s[1][W-1] != '#'){
    cout << "No" << endl;
    return 0;
  }

  if(s[H-1][0] == '#' && s[H-2][0] != '#' && s[H-1][1] != '#'){
    cout << "No" << endl;
    return 0;
  }

  if(s[H-1][W-1] == '#' && s[H-2][W-1] != '#' && s[H-1][W-2] != '#'){
    cout << "No" << endl;
    return 0;
  }


//行列の4辺
  for(int j=1; j<W-1; j++){
    if(s[0][j] == '#'){
      if(s[1][j] != '#' && s[0][j-1] != '#' && s[0][j+1] != '#'){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  for(int j=1; j<W-1; j++){
    if(s[H-1][j] == '#'){
      if(s[H-2][j] != '#' && s[H-1][j-1] != '#' && s[H-1][j+1] != '#'){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  for(int i=1; i<H-1; i++){
    if(s[i][0] == '#'){
      if(s[i-1][0] != '#' && s[i+1][0] != '#' && s[i][1] != '#'){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  for(int i=1; i<H-1; i++){
    if(s[i][W-1] == '#'){
      if(s[i-1][W-1] != '#' && s[i+1][W-1] != '#' && s[i][W-2] != '#'){
        cout << "No" << endl;
        return 0;
      }
    }
  }



  for(int i=1; i<H-1; i++){
    for(int j=1; j<W-1; j++){
      if(s[i][j] == '#'){
        if(s[i-1][j] != '#' && s[i+1][j] != '#' && s[i][j-1] != '#' && s[i][j+1] != '#'){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 3010;
int a[maxn];
int main()
{
    int n; scanf("%d", &n);
    int sum = 0;
    for(int i = 0; i < n; i++){
        int t;
        scanf("%d", &t);
        sum += (t-1);
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int count = 0;
		for(int i = 1; i < n; i++) {
			count += (n - 1) / i;
		}
		
		System.out.println(count);
		
	}

}


Measured memory_bytes: 35696
#include <iostream>
#include <vector>
#include <map>  
#include <string>
#include <algorithm>
using namespace std;

int main() {

    std::string S;
    cin >> S;

    const int N = 13;

    //dp[k] -> 13で割った余りがkのパターン
    std::vector<long>  dp(N);
    dp[0] = 1;


    //後ろから解くアルゴリズム
    // 1?2?3    0 -> 3 -> ?3 -> 2?3 -> ...
    long mod = 1000000007;

    int mul =1;
    for (int i = S.size() - 1; i >= 0; i--){

        std::vector<long>  nextDP(N);

        char c = S[i];
        if (c == '?'){
            for(int k =0; k< 10; k++){
                for(int j=0; j < N; j++){
                    nextDP[(k * mul + j) % N] += dp[j];
                    nextDP[(k * mul + j) % N] %= mod;
                }
            }
        }
        else{
            int k = (int)(S[i] - '0');
            for (int j = 0; j < N; j++){
                nextDP[(k * mul + j) % N] += dp[j];
                nextDP[(k * mul + j) % N] %= mod;                
            }
        }

        mul *= 10;
        mul %= N;
        dp = nextDP;
    }

    cout << dp[5] << endl;
    return 0;
}

Measured memory_bytes: 512