akhauriyash/Code-Regression huggingface dataset:
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

/*
9 3 4
5 2
ULLR
RDDD
*/

fn main() {
    let (H, W, N) = read!(usize, usize, usize);
    let (Y, X) = read!(usize, usize);
    let S = rl().chars().collect::<Vec<_>>();
    let T = rl().chars().collect::<Vec<_>>();

    let mut safe = true;

    for &(X, W, R, L) in &[(X, W, 'R', 'L'), (Y, H, 'D', 'U')] {
        debug!((X, W, R, L));

        let mut l = 1;
        let mut r = W;

        for i in (0..N).rev() {
            // aoki
            if i != N - 1 {
                if T[i] == L && r + 1 <= W {
                    r += 1;
                }
                if T[i] == R && l - 1 >= 1 {
                    l -= 1;
                }
            }
            debug!((i, "aoki", l, r));

            // takahashi
            if S[i] == L {
                l += 1;
            }
            if S[i] == R {
                r -= 1;
            }
            safe = safe && 1 <= l && l <= r && r <= W;

            debug!((i, "taka", l, r));
        }

        safe = safe && l <= X && X <= r;
    }

    println!("{}", if safe { "YES" } else { "NO" })
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n;
	string s;
	cin >> n >> s;

	int ans = 0, cnt = 0;
	for (char c : s) {
		if (c == 'I')
			cnt++;
		else
			cnt--;
		chmax(ans, cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
"""
# 標準入力取得
## 文字列
     = 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(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    N, M = map(int, sys.stdin.readline().split())
    like = [0 for _ in range(M)]
    for _ in range(N):
        ans = list(map(int, sys.stdin.readline().split()))
        for a in ans[1::]:
            like[a - 1] += 1

    cnt = 0
    for l in like:
        if l == N:
            cnt += 1

    print(cnt)


Measured memory_bytes: 5332
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
int h,w;
char c[50][50];
int d[50][50];
int num;
int X[4]={0,-1,0,1},Y[4]={-1,0,1,0};
int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c[i][j];
            if(c[i][j]=='.')num++;
        }
    }
    d[0][0]=1;
    queue<pair<int,int>> que;
    que.push(make_pair(0,0));
    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        int x=p.first,y=p.second;
        for(int i=0;i<4;i++){
            int nx=x+X[i],ny=y+Y[i];
            if(nx<0||h<=nx||ny<0||w<=ny||c[nx][ny]=='#'||d[nx][ny]!=0)continue;
            d[nx][ny]=d[x][y]+1;
            que.push(make_pair(nx,ny));
        }
    }
    if(d[h-1][w-1]==0)cout<<-1<<endl;
    else cout<<num-d[h-1][w-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long

using namespace std;

void solve()
{
	string s;
	cin>>s;
	ll a=0,b=0;

	for (int i = 0; i < s.length(); ++i)
	{
		if(s[i]=='A')a++;
		else b++;		/* code */
	}
	if(a>0 && b>0)cout<<"Yes";
	else cout<<"No";
}

int32_t main() 
{
	IOS	
	ll T=1;
	 // cin>>T;
	while(T--)
	{
    		solve();
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] houseInfo = new int[n];
		for(int i =0; i < n;i++ ) {
			houseInfo[i] = sc.nextInt();
		}

		int[] kyoriInfo = new int[n];
		for(int i =0; i < n;i++ ) {
			if(i == n -1) {
				kyoriInfo[i] = k - houseInfo[i] + houseInfo[0];
			}else {
				kyoriInfo[i] = houseInfo[i+1] - houseInfo[i];
			}
		}
		int answer = 0;
		int max = 0;
		for(int i =0; i < n;i++ ) {
			answer += kyoriInfo[i];
			if(max <  kyoriInfo[i]) {
				max = kyoriInfo[i];
			}
		}
		System.out.println(answer -max);
	}
}

Measured memory_bytes: 76084
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int n; ll a, b, x1, x2, ans = 0; cin >> n >> a >> b >> x1;
	for (int i = 1; i < n; i++) {
		cin >> x2; ans += min(a*(x2 - x1), b);
		x1 = x2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*  ex 7_3
    ruuu0048 */
#include <stdio.h>
#include <stdlib.h>

int main(void){

    int height,wide; //高さと横幅の変数を宣言
    char **table;

    scanf("%d %d",&height,&wide); //高さと変数を宣言

    //各行へのポインタ分のメモリ領域を確保
    table =(char**)calloc(height,sizeof(char*));
    //確保できなかったらプログラム終了
    if(table == NULL){
        exit(1);
    }

    //各行の要素分のメモリ領域を確保
    for(int i = 0;i < height; i++){
        table[i] = (char*)calloc(wide,sizeof(char));
        //それぞれで確保できなかったらプログラム終了
        if(table[i]==NULL){
            exit(1);
        }
    }


    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j <wide; j++)
        {
            scanf(" %c",&table[i][j]); //白黒を入力
        }   
    }

    
    for (int i = 0; i < height; i++)
    {
        int count = 0; //数える変数を宣言
        for (int j = 0; j <wide; j++)
        {
            if(table[i][j] == '#'){ //黒があったら
                count ++; //カウントする
            }
        }
        if (count == 0){ //i行目に一つも黒がなかったら
            for(int j = 0; j <wide; j++)
            {
                table[i][j] ='!'; //i行目をすべて'!'にする
            }
        }
    }

    for (int j= 0; j < wide; j++) //iとjを入れ替えて同じことをする
    {
        int count = 0;
        for (int i = 0; i <height; i++)
        {
            if(table[i][j] == '#'){
                count ++;
            }
        }
        if (count == 0){ //j列目に一つも黒がなかったら
            for(int i = 0; i <height; i++)
            {
                table[i][j] ='!'; //i行目をすべて'!'にする
            }
        }
    }

    //出力
    for (int i = 0; i < height; i++)
    {
        int count = 0; //数える変数を宣言
        for (int j = 0; j <wide; j++)
        {
            if(table[i][j] != '!'){ //!じゃなかったら
                printf("%c",table[i][j]); //出力
                count ++; //数える
            }
        }
        if(count > 0){ //一回でも出力してたら
            printf("\n"); //改行を出力
        }
    }
    
    //メモリ領域の開放
    //各行の要素分の領域を開放
    for(int i = 0; i < height; i++){
        free(table[i]);
    }
    //各行への配列へのポインタの領域を開放
    free(table);

    return 0; 
}

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

int main(){
   string s;
   cin >> s;
       if(s.at(0) != s.at(1) && s.at(0) != s.at(2) && s.at(1) != s.at(2)){
           cout << "Yes" << endl;
       }else{
       cout << "No" << endl;
       }
   }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

int Roundup(int a,int b){
    return (a+b-1)/b;
}


signed main(void){
    int H,W,N;
    cin >> H >> W >> N;
    cout << Roundup(N,max(H,W)) << endl;
    
    return 0;
}



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

typedef long long ll;
const ll mod = 1e9 + 7;
map<ll, ll>mp;

inline ll f(ll x) {
	if (mp[x])return mp[x];
	return mp[x] = (f(x / 2) + f((x - 1) / 2) + f((x - 2) / 2)) % mod;
}

int main() {
	ll n; cin >> n;
	mp[0] = 1, mp[1] = 2;
	cout << f(n) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    int s=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<k;i++)
    {

        s+=a[i];
    }
   cout<<s;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int D = sc.nextInt();
        
        switch( D ){
            case 25 :
                System.out.println("Christmas");
                break;                
            case 24 :
                System.out.println("Christmas Eve");
                break;                
            case 23 :
                System.out.println("Christmas Eve Eve");
                break;                
            case 22 :
                System.out.println("Christmas Eve Eve Eve");
                break;
        }
    }
}


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

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    vector<int> p;
    for(int j=1;j<=100;j++){
        if(a%j==0 && b%j==0){
            p.push_back(j);
        }
    }
    
    cout<<p[p.size()-k]<<endl;
}

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

int main() {
  int N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  
  vector<vector<int>> dp(3, vector<int>(N, 0));
  for (int i = 0; i < K; ++i) {
    if (T[i] == 's') dp[0][i] = R;
    if (T[i] == 'p') dp[1][i] = S;
    if (T[i] == 'r') dp[2][i] = P;
  }
  for (int i = K; i < N; ++i) {
    dp[0][i] = max(dp[1][i - K], dp[2][i - K]);
    dp[1][i] = max(dp[0][i - K], dp[2][i - K]);
    dp[2][i] = max(dp[0][i - K], dp[1][i - K]);
    if (T[i] == 's') dp[0][i] += R;
    if (T[i] == 'p') dp[1][i] += S;
    if (T[i] == 'r') dp[2][i] += P;
  }
  int ans = 0;
  for (int i = N - K; i < N; ++i) ans += max(max(dp[0][i], dp[1][i]), dp[2][i]);
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner;
 
public class Main{
		
	public static void main(String args[]){
		  
	    Scanner sc = new Scanner(System.in);
	    int R = sc.nextInt();
	    int G = sc.nextInt();
	    int B = sc.nextInt();
	    int N = sc.nextInt();
	    
	    int cnt = 0;
	    for(int r = 0; r <= N; r++) {
	    	for(int g = 0; g <= N; g++) {
	    		int b = (N-(R*r+G*g))/B;
	    		if(b >= 0 && R*r+G*g+B*b == N) {
	    			cnt++;
	    		}
	    	}
	    }
	    
	    System.out.println(cnt);
	}
}


Measured memory_bytes: 21844
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s;
    cin >> s;

    int n = s.size();

    bool p = true;

    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - i - 1]) {
            p = false;
        }
    }

    for (int i = 0; i < (n - 1) / 2; i++) {
        if (s[i] != s[(n - 1) / 2 - i - 1]) {
            p = false;
        }
    }

    for (int i = 0; i < (n - 1) / 2; i++) {
        if (s[n / 2 + 1 + i] != s[n - i - 1]) {
            p = false;
        }
    }

    cout << (p ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<cstdlib>
#define  ll long long
using namespace std;
const ll mod=1e9+7;
ll a[500000];
ll n,m,i,j,k,t,ans,x,y;
ll read()
{
	ll f=0,c=1;	char ch=getchar();
	while((ch<'0')||(ch>'9'))	{	if(ch=='-') c=-1;	ch=getchar();	}
	while((ch>='0')&&(ch<='9'))	{	f=f*10+ch-'0';	ch=getchar();	}
	return c*f;
}
int main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	n=read();
	for(ll i=1;i<=n;++i)	a[i]=read();
	k=1;
	for(ll t=1;t<=64;++t)
	{
		x=0; y=0;
		for(ll i=1;i<=n;++i) if(a[i]&1) ++x; else ++y;
		for(ll i=1;i<=n;++i) a[i]>>=1;
		ans=( ans + x * y % mod * k % mod ) % mod ;
		k=k*2%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    string s;
    cin >> s;
    int n = s.size()+1;
    int a[n] = {};
    for (int i = 0; i < n-1; i++) {
        if (s[i] == '<') {
            a[i+1] = max(a[i+1], a[i]+1);
        }
    }
    for (int i = n-2; i >= 0; i--) {
        if (s[i] == '>') {
            a[i] = max(a[i], a[i+1]+1);
        }
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 2820
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;

int count(int n, vector<int> e){
    int cnt = 0;
    for (int i = 0; i < e.size(); i++){
        if (e[i] >= n - 1) cnt++;
    }
    return cnt++;
}

int main(){
    int n;
    cin >> n;
    vector<int> e(n+1, 0);

    // n! の 1, 2, ..., n それぞれに対して素因数分解をする
    // これらを合算することで n! の素因数分解とする
    // これにより n! の約数が列挙できた
    for (int i = 2; i <= n; i++){
        int tmp = i;
        for (int j = 2; j <= i; j++){
            while (tmp % j == 0){
                e[j]++;
                tmp /= j;
            }
        }
    }

    // 約数の数が 75 個になる七五数の数を数える
    // ある数 N の約数の個数は、N = 2^a * 3^b * ... * p^n、より
    // (a + 1) * (b + 1) * ... * (p + 1) 通りとなる
    // 指数部の組み合わせは、75 = 3 * 5 * 5より、
    // (3, 5, 5)、(15, 5)、(25, 3)、(75) の4通りある
    // n! の約数のうち上記の条件を満たすものを数え上げる
    int ans = count(75, e) + count(25, e) * (count(3, e) - 1) + count(15, e) * (count(5, e) - 1) + count(5, e) * (count(5, e) - 1) * (count(3, e) - 2) / 2;
    cout << ans << endl;

    return 0;
}

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

using namespace std;
 
int main(){

  while(1){

    string cards;
    cin >> cards;
    
    if(cards=="-")
      break;
    
  	int m;
    cin >> m;

    int h;
    for(int i=0; i<m; i++){
      	cin >> h;
  		cards = cards.erase(0, h) + cards.substr(0, h);
    }
  	cout << cards <<endl;
  }
  
  return 0;

  
}


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

using namespace std;

typedef long long ll;

const double eps = 0.00001;
const int MOD = 1000000007; //998244353
const int INF = 1070000055;
const long long LINF = 1223372000000000555;
const int N = 1050555;
const int M = 6525;

void solve(){
    string s, t;
    cin >> s >> t;

    int n = s.size(), m = t.size();

    ll ans = LINF;
    for (int i = 0; i < n; i++){
        if (i + m - 1 >= n) continue;
        ll z = 0;
        for (int j = 0; j < m; j++){
            if (s[i + j] != t[j]) z++;
        }
        ans = min(ans, z);
    }

    cout << ans;

}


int main() {
    ios_base::sync_with_stdio(false);
#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, x[101010], l[101010];
P s[101010];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> l[i];
		s[i] = P(x[i]+l[i], i);
	}
	
	sort(s,s+n);
	
	i64 ans = 0, cnt = -INF;
	for(int i = 0; i < n; i++){
		if(cnt > s[i].first - l[s[i].second]*2) continue;
		cnt = s[i].first;
		ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2560
function main(input) {
  var a = input[0]-0;
  var ans = 0;
  for(var i=0;i<=Math.sqrt(a);i++){
    if(i*i<=a) ans = i*i;
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


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

int main() {
	long long int x,k,d;

	cin>>x>>k>>d;
    x=abs(x);
    if(x>0 && (x/d)>=k){
        long long qq=x/d;
        x=x-(k)*d;
        cout<<x;
        return 0;
    }
    long long y=x/d;
    x-=y*d;
    k-=y;
    if(k%2==0)
        cout<<abs(x);
    else
        cout<<min(abs(x-d),abs(x+d));
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

typedef pair<int,int> P;

struct edge {
  int to,cost;
};

int d[100000];

int main(){

  int n;
  cin >> n;
  vector<vector<edge> > G(n);
  for (int i=0; i<n; i++) {
    int k=0;
    edge e;
    cin >> e.to;
    if (e.to!=0){
      if (0<e.to && e.to<7)k = e.to;
      e.to+=i;
      e.cost=0;
      G[i].push_back(e);
    } else {
      for (int d=1;d<7;d++){
        if (k==d)continue;
        if (i+d>=n)continue;
        edge e;
        e.to = i+d;
        e.cost = 1;
        G[i].push_back(e);
      }
    }
  }
  for (int i=0;i<n;i++){
    for(int j=0;j<G[i].size();j++){
      edge e=G[i][j];
      // cout << "from " << i << " to " << e.to << " with "<< e.cost << endl;
    }
  }

  priority_queue<P, vector<P>, greater<P> > que;
  d[0] = 0;
  for (int i=1; i<n; i++) {
    d[i] = 1e9;
  }
  que.push(P(0,0));

  while(!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    int c = p.first;
    // cout << c << v << endl;
    if (d[v] < c) continue;
    for (int i=0; i<G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v]+e.cost){
        d[e.to] = d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
  // for (int i=0; i<n; i++) {
  //    cout << d[i] << endl;
  // }
  cout << d[n-1] << endl;

  return 0;
}

Measured memory_bytes: 10224
#include <stdio.h>

void bombs(int s[10][10], int x, int y){
  int i;
  
  if(x < 0 || y < 0 || x >= 8 || y >= 8 || s[y][x] == 0) return;
  s[y][x] = 0;
  for(i = 1;i <= 3;i++){
    bombs(s, x, y - i);
    bombs(s, x, y + i);
    bombs(s, x - i, y);
    bombs(s, x + i, y);
  }
}

int main(){
  int n, x, y, i, j, k;
  char a[8];
  scanf("%d", &n);

  for(i = 1;i <= n;i++){
    int surface[10][10] = {};
    for(j = 0;j < 8;j++){
      scanf("%s", a);
      for(k = 0;k < 8;k++){
	surface[j][k] = a[k] - '0';
      }
    }

    scanf("%d%d", &x, &y);

    bombs(surface, x - 1, y - 1);

    printf("Data %d:\n", i);
    for(j = 0;j < 8;j++){
      for(k = 0;k < 8;k++)
	printf("%d", surface[j][k]);
      puts("");
    }
  }
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <set>
#define ll long long
using namespace std;

int pp[100010];

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i){
		int P;
		cin >> P;
		pp[P]=i;
	}
	multiset<ll> ms{-1, -1, N, N};
	ll ans=0;
	for(int i=N; i>0; --i){
		auto it=ms.insert(pp[i]);
		--it;
		--it;
		ll cc[5];
		for(int j=0; j<5; ++j){
			cc[j]=*it;
			++it;
		}
		ans += ((cc[1]-cc[0])*(cc[3]-cc[2])+(cc[2]-cc[1])*(cc[4]-cc[3]))*i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, int>;
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
const ll mod = 1e9 + 7;
const ll inf = 1e12;
const double pi = 3.141592;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a+2), t(b+2);
    rep(i, a) cin >> s[i+1];
    rep(i, b) cin >> t[i+1];
    s[0] = -inf;
    t[0] = -inf;
    s[a + 1] = inf;
    t[b + 1] = inf;
    rep(i, q)
    {
        ll x;
        cin >> x;
        int si = lower_bound(s.begin(), s.end(), x) - s.begin();
        int ti = lower_bound(t.begin(), t.end(), x) - t.begin();
        ll tmp1 = max(s[si] - x, t[ti] - x);
        ll tmp2 = max(x - s[si - 1], x - t[ti-1]);
        ll tmp3 = s[si] - t[ti - 1] + min(s[si] - x, x - t[ti - 1]);
        ll tmp4 = t[ti] - s[si - 1] + min(t[ti] - x, x - s[si - 1]);
        ll tmpans = min({tmp1, tmp2, tmp3, tmp4});
        cout << tmpans << "\n";
    }
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    int n, m;
    cin >> n >> m;
    unordered_map<int, int> mp;
    for (int i = 0; i < n; ++i) {
        int k;cin >> k;
        for (int j = 0; j < k; ++j) {
            int t;
            cin >> t;
            mp[t]++;
        }
    }
    int c = 0;
    for (auto i : mp) {
        if (i.second == n) c++;
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;


int main(){
   int n,x;
   cin>>n>>x;
   int m[110];
   int minm=1100;
   for(int i=0;i<n;i++){
      cin>>m[i];
      minm=min(minm,m[i]);
   }
   int ans=0;
   for(int i=0;i<n;i++){
      x-=m[i];
   }
   ans=n+x/minm;
   cout<<ans<<endl;
   
   
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    // return true if xy1 is farer
    static boolean isFarer(int[] xy1, int[] xy2) {
        double dist2 = (Math.pow(xy1[0], 2) + Math.pow(xy1[1], 2)) - (Math.pow(xy2[0], 2) + Math.pow(xy2[1], 2));
        if (dist2 > 0)
            return true;
        else if (dist2 < 0)
            return false;

        return xy1[0] > xy2[0];
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine().trim());
        int[] pos;
        int[] treasure;
        int[] move;
        for (int j = 0; j < n; j++){
            pos = new int[2];
            treasure = new int[2];
            move = new int[2];
            while (true) {
                String[] line = sc.nextLine().split(" ");
                for (int i = 0; i < 2; i++) {
                    move[i] = Integer.parseInt(line[i]);
                }

                if (move[0] == 0 && move[1] == 0)
                    break;

                pos[0] = pos[0] + move[0];
                pos[1] = pos[1] + move[1];

                if (isFarer(pos, treasure)) {
                    System.arraycopy(pos, 0, treasure, 0, 2);
                }

            }
            System.out.println(treasure[0] + " " + treasure[1]);
        }
    }
}

Measured memory_bytes: 34288
#include<iostream>
using namespace std;
int main(){
  string S;
  string T;
  int count =0;
  int max=0;
  cin >> S >> T;
  for(int i=0; i<S.size()-T.size()+1;i++){
    for(int j=0; j<T.size(); j++){
      if(S.at(i+j)==T.at(j)){
        count++;
      }
    }
    if(max< count){
      max=count;
    }
    count=0;
  }
  cout<< T.size()-max<< endl;
}

  
      
        


Measured memory_bytes: 3644
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

void solve()
{
    IN(a, b, c);
    if (a + b + c>= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,n) loop(i,0,n)

using namespace std;

inline void pon(int n){
    cout << n << endl;
    fflush(stdout);
}

inline int get(){
    int res;
    cin >> res;
    return res;
}

int main(){
    srand(time(0u)+getpid());

    int n; cin>>n;
    vector<string> win(n);
    rep(i,n)cin>>win[i];

    int hand = rand()%n;
    rep(i,1000){
        pon(hand+1);
        int ai_hand = get()-1;
        if (win[hand][ai_hand] == 'x')hand = rand()%n;
    }
}

Measured memory_bytes: 1328
// vim: shiftwidth=2 expandtab foldmethod=marker

// include {{{
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <utility>
#include <cstdlib>
// }}}

// debug(...) {{{
#ifdef LOCAL_DEBUG
#include "./debug.h"
#else
#define debug(...)
#endif
// }}}

// misc {{{
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

template<class T>
void sort(T& arr) {
  std::sort(arr.begin(), arr.end());
}
template<class T, class By>
void sort_by(T& arr, By by) {
  std::sort(arr.begin(), arr.end(), [by](auto l, auto r){return  by(l) < by(r); });
}

template<class T>
void reverse(T& arr) {
  std::reverse(arr.begin(), arr.end());
}

// }}}


// main {{{
void solve();
int main() {
  solve();
}
// }}}

void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<pair<int, int>> BC(M);
  rep(i, M) {
    int b, c;
    cin >> b >> c;
    BC[i] = make_pair(b, c);
  }

  sort_by(BC, [](auto x){ return make_pair(x.second, x.first); });
  reverse(BC);
  sort(A);

  debug(A);
  debug(BC);

  int i = 0, j = 0;
  ll sum = 0;
  while(i < N && j < M) {
    int b = BC[j].first;
    int c = BC[j].second;
    debug(j, A[i], b, c);
    while(i < N && A[i] < c && b > 0) {
      sum += c;
      --b;
      ++i;
    }
    ++j;
  }
  while(i < N) { sum += A[i]; ++i; }
  cout << sum << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;
	cin >> s;
	int n = s.size();
	char x = s[0];
	int counter = 1;
	for(int i = 1; i < n; i++) {
		if (counter < 3){
			if(s[i] == x){
				counter++;
			}
			else{
				counter = 1;
				x = s[i];
			}
		}
		else{
			break;
		}
	}

	if(counter >= 3){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;
int main(){
  string t;
  cin >> t;
  rep(i, t.size()){
    if(t[i] == '?'){
      cout << 'D';
    }
    else{
      cout << t[i];
    }
  }
  
 cout << endl;
}
    




Measured memory_bytes: 3748
def main():
    input()
    a = list(map(int, input().split()))
    s = 1
    if 0 in a:
        s = 0
    else:
        for i in a:
            s *= i
            if s > 10 ** 18:
                s = -1
                break
    print(s)

if __name__ == '__main__':
    main()

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

int main(){
    int n;
    cin >> n;
    int A[n][n];
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> A[i][j];
    int p = int(1e9) + 7;

    int DP[1 << n];
    memset(DP, 0, sizeof(DP));
    DP[0] = 1;

    for (int S = 1; S < 1 << n; S++){
        int i = __builtin_popcount(S) - 1;
        int s = 0;
        for (int j = 0; j < n; j++)
            if (A[i][j]) s = (s + DP[S & ~(1 << j)]) % p;
        DP[S] = s;
    }

    cout << DP[(1 << n) - 1] << endl;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
bool tab[1001][1001];
int dp[1001][1001];
int main(){
    boost;
    int n,m;
    cin>>n>>m;
    char car;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
        {
            dp[i][j]=0;
            cin>>car;
            if(car=='.')tab[i][j]=1;
            else tab[i][j]=0;
        }
    dp[0][0]=1;
    for (int i = 1; i < n; ++i)
        if(tab[i][0])
            dp[i][0]=dp[i-1][0];
    for (int i = 1; i < m; ++i)
        if(tab[0][i])
            dp[0][i]=dp[0][i-1];
    for (int i = 1; i < n; ++i)
        for (int j = 1; j < m; ++j)
            if(tab[i][j])
                dp[i][j]=(dp[i-1][j]%MOD+dp[i][j-1]%MOD)%MOD;
    cout<<dp[n-1][m-1];
    return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    int n,p;
    //cin>>n>>p;
    string s;
    cin>>s;
    n = s.length(),p=2019;
    //int n = s.length();
    //int p = 2019;
    Re(s);
    int64_t num=0;
    vector<int64_t> a(n+1);
    a[0]=0;
    rep(i,n){
        num=num+modpow(10%p,i,p)*(s[i]-'0')%p;
        num%=p;
        a[i+1]=num;
    }
    vector<int64_t> cnt(p+1,0);
    rep(i,n+1) cnt[a[i]]++;
    int64_t ans=0;
    rep(i,p){
        ans+=cnt[i]*(cnt[i]-1)/2;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 5240
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
class UnionFind {
private:
    int sz;
    vector<int> par, size_;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x,int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};

vector<vector<int> > g;
bool pp[701][701];
int c[701];
bool ng = 0;
void dfs(int id,int pre,int col){
    c[id] = col;
    for(auto x:g[id]){
        if(x==pre)continue;
        if(c[x]==0){
            dfs(x,id,3-col);
        }else{
            if(c[x]==col)ng = true;
        }
    }
}
int d[701][2];
int main(){
    int n,m;
    cin >> n >> m;
    g.resize(n);
    rep(i,n){
        pp[i][i] = 1;
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        pp[a][b] = 1;
        pp[b][a] = 1;
    }
    UnionFind uf(n);
    rep(i,n){
        rep(j,n){
            if(!pp[i][j]){
                uf.unite(i,j);
                g[i].push_back(j);
            }
        }
    }
    bool used[701]={};
    rep(i,n){
        if(used[uf.find(i)])continue;
        used[uf.find(i)] = 1;
        dfs(i,-1,1);
    }
    if(ng){
        cout << -1 << endl;
        return 0;
    }
    rep(i,n){
        d[uf.find(i)][c[i]-1]++;
    }
    bool dp[701][701]={};
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(dp[i][j]){
                dp[i+1][j+d[i][0]] = 1;
                dp[i+1][j+d[i][1]] = 1;
            }
        }
    }
    int mi = inf;
    for(int i=0;i<n;i++){
        if(dp[n][i]){
            chmin(mi,(i*(i-1))/2+((n-i)*(n-i-1)/2));
        }
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 3584
import sys
import collections
import itertools
import operator
import bisect
import heapq
import fractions
import math as mt
import copy
import numpy
import scipy

N=int(input())
L=list(map(int,input().split()))

lst=list(itertools.combinations(L,3))
cnt=0
for a in lst:
  if a[0]>abs(a[1]-a[2]) and a[0]<a[1]+a[2] and a[0]!=a[1] and a[0]!=a[2] and a[1]!=a[2]:
    cnt+=1
print(cnt)

Measured memory_bytes: 42716
program kudamono
read*,n,k
call fruit(n,k)

end program

subroutine fruit(n,k)
integer::p(1:n)
integer::a(1:n)

read*,(p(j),j=1,n)
do i=n,2,-1
 do j=1,i-1
  if (p(j)>p(j+1)) then
   ntemp=p(j)
   p(j)=p(j+1)
   p(j+1)=ntemp
  end if
 end do
end do 
isum=0
do i=1,k
isum=isum+p(i)
end do
print*,isum
end subroutine fruit

Measured memory_bytes: 2880
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
S = S.replace("BC", "X")
S = S.replace("B", "C")

L = S.split("C")
ans = 0
for l in L:
    X_num = l.count('X')
    for c in l:
        if c == "X":
            X_num -= 1
        else:
            ans += X_num
print(ans)


Measured memory_bytes: 5540
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 998244353;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, s; cin >> n >> s;
    vll a(n);
    for (ll i = 0; i < n; i++) cin >> a[i];
    vvll dp(n + 1, vll(s + 1, 0));
    dp[0][0] = 1;
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j <= s; j++) {
            (dp[i + 1][j] += dp[i][j]) %= MOD;
            if (j + a[i] <= s) {
                if (j == 0) {
                    if (a[i] == s) (dp[i + 1][s] += (i + 1) * (n - i) % MOD) %= MOD;
                    else (dp[i + 1][a[i]] += i + 1) %= MOD;
                } else if (j + a[i] == s) (dp[i + 1][s] += (dp[i][j] * (n - i) % MOD)) %= MOD;
                else (dp[i + 1][j + a[i]] += dp[i][j]) %= MOD;
            }
        }
    }

    // for (ll i = 1; i <= n; i++) DEBUG_VLL(dp[i])
    cout << dp[n][s] << '\n';
    return 0;
}


Measured memory_bytes: 70784
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
int N;
vector<int> G[102];
int f[102];
int f2[102];
int search(int id){
  int ret=0;
  for(int i=0;i<(int)G[id].size();i++){
    if(!f2[G[id][i]]){
      f[G[id][i]]=1;
      f2[G[id][i]]=1;
      ret = max(ret,search(G[id][i])+1);
      f2[G[id][i]]=0;
    }
  }
  return ret;
}
int search2(int id){
  int ret=0;
  for(int i=0;i<(int)G[id].size();i++){
    if(!f2[G[id][i]] && !f[G[id][i]]){
      f2[G[id][i]]=1;
      ret = max(ret,search(G[id][i])+1);
      f2[G[id][i]]=0;
    }
  }
  return ret;
}
int solve(int id){
  int ret=0;
  if((int)G[id].size()==1){
    if(!f[G[id][0]]){
      f[G[id][0]]=1;
      f2[G[id][0]]=1;
      ret = search(G[id][0])+1;
      f2[G[id][0]]=0;
    }
    return ret;
  }
  for(int i=0;i<(int)G[id].size();i++){
    for(int j=i+1;j<(int)G[id].size();j++){
      int tmpi=0,tmpj=0;
      bool fi=false,fj=false;
      if(!f[G[id][i]]){
    fi=true;
    f[G[id][i]]=1;
    f2[G[id][i]]=1;
    tmpi = search(G[id][i])+1;
    f2[G[id][i]]=0;
      }
      if(!f[G[id][j]]){
    fj=true;
    f[G[id][j]]=1;
    f2[G[id][j]]=1;
    tmpj = search2(G[id][j])+1;
    f2[G[id][j]]=0;
      }
      ret = max(ret,tmpi+tmpj);
    }
  }
  return ret;
}
int main(){
  while(1){
    scanf("%d",&N);
    if(!N) break;
    for(int i=0;i<N;i++){
      int a,b;
      scanf("%d %d",&a,&b);
      G[a].push_back(b);
      G[b].push_back(a);
    }
    int res=0;
    for(int i=0;i<102;i++){
      if(!G[i].empty()){
    memset(f,0,sizeof(f));
    f[i]=1;
    f2[i]=1;
    //      printf("wa:%d size %d\n",i,(int)G[i].size());
    int st = solve(i)+1;
    f2[i]=0;
    res = max(res,st);
    //     printf("wa ... %d %d\n",i,st);
      }
    }
    printf("%d\n",res);
    for(int i=0;i<102;i++) G[i].clear();
  }
}

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

using namespace std;

const int Mod = 1e9 + 7, N = 25, MaxMM = (1<<19) + 5;

int n, m, i, j, k, mask, MM, restriction[N], valuare[N], x, y, dir, dp[N][MaxMM];


void add(int &a, int b)
{
    a += b;
    if(a >= Mod) a -= Mod;
}

bool good(int pos, int mask)
{
    return ((mask & restriction[pos]) == valuare[pos]);
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n >> m >> k;
    while(k--)
    {
        cin >> x >> y >> dir;
        restriction[x] |= (1 << (y-1));
        if(dir) valuare[x] |= (1 << (y-1));
    }

    MM = (1<<(n-1)) - 1;
    for(mask = 0; mask <= MM; ++ mask)
        dp[0][mask] = good(1, mask);

    for(i=2; i<=m; ++i)
    {
        for(j=0; j<n-1; ++j)
            for(mask = 0; mask <= MM; ++ mask)
            {
                add(dp[j+1][mask], dp[j][mask]);
                if( !(mask & (1<<j)) )
                {
                    int new_mask = mask & (MM - (1<<(j+1)) + 1);
                    new_mask = new_mask & (-new_mask);
                    add(dp[j+1][ (mask ^ new_mask) | (1<<j) ], dp[j][mask]);
                }
            }

        for(mask = 0; mask <= MM; ++ mask)
            dp[0][mask] = good(i, mask) * dp[n-1][mask];

        for(j=1; j<=n-1; ++j) memset(dp[j], 0, sizeof(dp[j]));
    }

    int ans = 0;
    for(mask = 0; mask <= MM; ++ mask)
            add(ans, dp[0][mask]);

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 43392
fun main(args: Array<String>) {
  val (n, x) = readLine()!!.split(" ").map { it.toInt() }
  val a = readLine()!!.split(" ").map { it.toLong() }
  var b = LongArray(n) { a[it] }
  var ans = arrayOf(b[0] - x, 0L).max()!!
  b[0] -= ans
  for (i in 1 until n) {
    val c = arrayOf(b[i - 1] + b[i] - x, 0L).max()!!
    ans += c
    b[i] -= c
  }
  println(ans)
}


Measured memory_bytes: 72400
nk = list(map(int, input().split()))
n= nk[0]
k=nk[1]
d=[]
a=[]
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int, input().split())))
count=[None] * n

for i in range(len(d)):
    if len(a[i]) == 0:
        count[a[i]-1] = True
    else:
        for j in range(len(a[i])):
            count[a[i][j]-1] = True

print(count.count(None))

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>> 
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FRE freopen("explicit.in","r",stdin);freopen("explicit.out","w",stdout)
#define mp make_pair
#define pll pair <lli,lli>
#define vll vector <lli>
#define pq2 priority_queue<pair<lli,lli>>
#define f first
#define s second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define all(x) x.begin(), x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define ld long double 
const long double pi = 3.1415926535898;
#define dec greater<lli>()
const lli mod=1000000007;
//const lli mod=100000000;
using namespace std;
lli lcm (lli a, lli b) {return ((a*b)/__gcd(a,b));}
lli modpower (lli a,lli b)
{
    if(b==0) return 1;
    lli c=modpower(a,b/2)%mod;
    if (b%2) return (((a*c)%mod)*c)%mod;
    else return (c*c)%mod;
}
lli power (lli a,lli b)
{
    if(b==0) return 1;
    lli c=power(a,b/2);
    if (b%2) return (a*c*c);
    else return c*c;
}
lli sieve (int n)
{
    bool qrr[n+1];
    for (int i=0;i<=n;i++)
    qrr[i]=1;qrr[0]=0;qrr[1]=0;
    for (int i=2;i*i<=n;i++)
    {
        if (qrr[i]==1)
        {
            for (int j=i*i;j<=n;j+=i)
            {qrr[j]=0;}
        }
    }
    return 0;
}
int main()
{
    fio;
    string s[4],tt;
    s[0]="AC";s[1]="WA";s[2]="TLE";s[3]="RE";
    lli t;
    cin>>t;
    lli a[4];
    mem(a,0);
    while (t--)
    {
        cin>>tt;
        for (int i=0;i<4;i++)
        {if (tt==s[i])a[i]++;}
    }
    for (int i=0;i<4;i++)
    cout<<s[i]<<" x "<<a[i]<<"\n";
    return 0;
}

Measured memory_bytes: 3656
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))

ans = []
for i in range(n):
  ans += [i+1]*a[i]

ans = [ans[i*w:(i+1)*w] if i%2 ==0 else ans[(i+1)*w-1:i*w-1:-1] for i in range(h)]
for c in ans:
    print(*c)

Measured memory_bytes: 3920
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	int g[2];
	cin>>g[0]>>g[1];
	vvi in(2);
	s+="T";
	int co=0,to=0;
	bool h=true;
	rep(i,s.size()){
		if(s[i]=='F')co++;
		else{
			if(h)g[0]-=co,h=0;
			else if(co)in[to].pb(co);
			to^=1;
			co=0;
		}
	}
//	rep(i,2){rep(j,in[i].size())cout<<" "<<in[i][j];cout<<endl;}
	h=true;
	rep(i,2){
		g[i]=abs(g[i]);
		int mi=0;
		rep(j,in[i].size())mi-=in[i][j];
		vi dp(8010);
		dp[0]=1;
		rep(j,in[i].size())for(int k=8010-1;k>=0;k--)
			if(dp[k]&&k+in[i][j]<8010)dp[k+in[i][j]]=1;
//		rep(j,10)cout<<" "<<dp[j];cout<<endl;
		bool H=false;
		if((g[i]-mi)%2==0&&dp[(g[i]-mi)/2])H=true;
		if(-g[i]-mi>=0&&(-g[i]-mi)%2==0&&dp[(-g[i]-mi)/2])H=true;
		if(!H)h=false;
	}
	if(h)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}




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

int main(){
	int k,s;
	cin >> k >> s;
	int ans = 0;
	for(int x = 0; x <= k; ++x){
		for(int y = 0; y <= k; ++y){
			int z = s - x - y;
			if(0<=z && z<=k){
				++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256