akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>


typedef long long LL;


const LL mod = (LL)(1e9) + 7;
const int MAXN = 307;


std::vector<std::pair<int, int> >q[MAXN];


LL dp[MAXN][MAXN][MAXN];


inline bool check(const int &r, const int &g, const int &b) { 
	int R = std::max(r, std::max(g, b));
	for (std::vector<std::pair<int, int> >::iterator iter = q[R].begin(); iter != q[R].end(); ++iter) {
		int l = iter->first, x = iter->second;
		if (r >= l) --x;
		if (g >= l) --x;
		if (b >= l) --x;
		if (x != 0) {
//std::cout << r << " "<< g << " " << b << std::endl;
			return false;
		}
	}
	return true;
}


int main() {
	int n, m;
	LL ans = 0;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);
		q[r].push_back(std::make_pair(l, x));
	}	
	dp[0][0][0] = 1;
	for (int r = 0; r <= n; ++r) {
		for (int g = 0; g <= n; ++g) {
			for (int b = 0; b <= n; ++b) {
				if (check(r, g, b) == false) {
					dp[r][g][b] = 0;
					continue;
				}
				else {
					int to = std::max(r, std::max(g, b)) + 1;
					if (to == n + 1) {
						ans = (ans + dp[r][g][b]) % mod;
					}
					else {
						dp[to][g][b] = (dp[to][g][b] + dp[r][g][b]) % mod;
						dp[r][to][b] = (dp[r][to][b] + dp[r][g][b]) % mod;
						dp[r][g][to] = (dp[r][g][to] + dp[r][g][b]) % mod;
					}
				}
			}
		}	
	}	
	std::cout << ans;
	return 0;
}


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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll N;

    cin >> N;

    cout << (N < 1000 ? "ABC" : "ABD") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int64_t solve(int64_t H){
	if(H==1){
    	return 1;
    }else{
    	return 1+2*solve(H/2);
    }
}

int main(){
	int64_t H;
    cin>>H;
    cout<<solve(H)<<endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 2e5+5;
int N, K, a[MAX];

int main(int argc, char** argv) {
	scanf("%d%d", &N, &K);
	rep(i, 0, N) scanf("%d", a+i);
	rep(i, K, N)
		printf("%s\n", (a[i] > a[i-K]) ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 4460
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
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 size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
s = sr()
rl = 0
default = 0
ret = 0
for i in range(n-1):
    if s[i] == 'R' and s[i+1] == 'L':
        rl += 1
    elif s[i] == s[i+1]:
        default += 1
if rl == 0:
    print(n-1)
else:
    ret = 0
    if s[0] != s[n-1]:
        ret = 1
        if s[n-1] == 'L':
            rl-=1
    ans = default
    ans += 2*min(rl, k)
    if k-rl > 0:
        ans+=ret
    print(ans)

Measured memory_bytes: 77568
# coding: utf-8
# Your code here!

import sys
from collections import defaultdict

S = input()

d = defaultdict(int)

for i in range(4):
    d[S[i]] += 1
    
for key in d.keys():
    if d[key] != 2:
        print('No')
        sys.exit()
        
print('Yes')

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;

struct Mint {
	static const ll mod = (ll)(1e9 + 7);
	ll val;

	Mint() { val = 0; }
	Mint(ll a) { val = a; verify_value(); }

	void verify_value() {
		if (val >= mod) val %= mod;
		if (val < 0) val %= mod, val += mod;
	}

	Mint pow(ll p) const {
		Mint cur = Mint(val), ret = 1;
		while (p > 0) {
			if (p & 1) ret *= cur;
			cur *= cur;
			p >>= 1LL;
		}
		return ret;
	}
	Mint inv() const {
		if (val == 0) cerr << "CAUTION: inv() is called with 0." << endl;
		return pow(mod - 2);
	}

	Mint operator+() const { return *this; }
	Mint operator-() const { return Mint(mod - val); }

	Mint operator+=(const Mint &a) {
		val += a.val;
		if (val >= mod) val -= mod;
		return Mint(val);
	}
	Mint operator*=(const Mint &a) {
		val *= a.val;
		if (val >= mod) val %= mod;
		return Mint(val);
	}
	Mint operator-=(const Mint &a) { return *this += -a; }
	Mint operator/=(const Mint &a) { return *this *= a.inv(); }

	Mint operator++() { return *this += Mint(1); }
	Mint operator--() { return *this -= Mint(1); }
	Mint operator++(int) {
		Mint ret = *this;
		++(*this);
		return ret;
	}
	Mint operator--(int) {
		Mint ret = *this;
		--(*this);
		return ret;
	}

	operator ll() const { return val; }
};

Mint operator+(const Mint &a, const Mint &b) {
	ll ret = a.val + b.val;
	if (ret >= Mint::mod) ret -= Mint::mod;
	return Mint(ret);
}
Mint operator*(const Mint &a, const Mint &b) {
	ll ret = a.val * b.val;
	if (ret >= Mint::mod) ret %= Mint::mod;
	return Mint(ret);
}
Mint operator-(const Mint &a, const Mint &b) { return a + (-b); }
Mint operator/(const Mint &a, const Mint &b) { return a * b.inv(); }

ostream &operator<<(ostream &out, const Mint &a) { return out << a.val; }
istream &operator>>(istream &in, Mint &a) {
	in >> a.val;
	a.verify_value();
	return in;
}


int main() {
	int n, k; cin >> n >> k;
	vector<vector<int>> edg(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		edg[a].push_back(b);
		edg[b].push_back(a);
	}

	bool vis[100005] = {};
	vector<Mint> cnt(n);
	vector<int> depth(n);

	Mint ans = 1;
	deque<pair<int, int>> que;
	que.emplace_back(0, -1);
	while (!que.empty()) {
		int pos = que.front().first, par = que.front().second;
		que.pop_front();
		vis[pos] = true;

		if (par != -1) depth[pos] = depth[par] + 1;
		Mint dep = depth[pos] >= 2 ? 2 : depth[pos];
		if (par != -1) dep += cnt[par];
		ans *= Mint(k) - dep;
		if (par != -1) cnt[par]++;

		for (int ch : edg[pos]) {
			if (vis[ch]) continue;
			que.emplace_back(ch, pos);
		}
	}
	cout << ans << endl;
	return 0;
}



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

const int N = 1e6+1;

map<int,int> mp;

int a[N],b[N];

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0; i<m; i++){
        cin>>a[i]>>b[i];
        if(b[i]==n) mp[a[i]]=1;
    }
    int flag = 0;
    for(int i=0; i<m; i++){
        if(a[i]==1){
            if(mp[b[i]]){
                flag = 1;
                cout << "POSSIBLE" << endl;
                break;
            }
        }
    }
    if(!flag) cout << "IMPOSSIBLE" << endl;
}


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

int main() {
	int n;cin>>n;
	int c=0;
	multiset<int> a;
	set<int> b;
	while(n--){
		int x;cin>>x;
		a.insert(x);
		b.insert(x);
	}
	for(auto i:b){
		if(a.count(i)>i){
			c+=a.count(i)-i;
		}
		else if(a.count(i)<i)
			c+=a.count(i);
		}
	cout<<c;
	return 0;
}


Measured memory_bytes: 12564
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,k) = get!(usize, usize);
    let s = get!(String).chars().collect::<Vec<_>>();

    let mut zflag = s[0] == '0';
    let mut count = 1;
    let mut kat = Vec::new();
    for i in 1..n {
        if zflag ^ (s[i] == '0') {
            kat.push(count);
            count = 0;
        }
        zflag = s[i] == '0';
        count += 1;
    }
    kat.push(count);


    let mut sums = kat.into_iter().scan(0, |sum, e| {
        *sum += e;
        Some(*sum)
    }).collect::<Vec<_>>();
    
    sums.insert(0,0);
    if s[0] == '0' {
        sums.insert(0, 0);
    }
    if s[n-1] == '0' {
        sums.push(n);
    }

    let mut mx = 0;
    for i in (0..sums.len()).filter(|e| e % 2 == 0).filter(|e| e+2*k+1<sums.len()) {
        mx = max!(mx, sums[i+2*k+1]-sums[i]);
    }
    if mx == 0 {
        mx = n;
    }

    println!("{}", mx);        
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

const int MAXN = 100005;

int GCD(int a, int b) {
    return (b == 0) ? a : GCD(b, a%b);
}

int n, m;
char s[MAXN], t[MAXN];

int main () {
    scanf("%d%d", &n, &m);
    scanf("%s", s);
    scanf("%s", t);

    int d = GCD(n, m);

    ll ans = 1LL*n*m/d;

    for(int i = 0, j = 0; i < n; i += n/d, j += m/d) {
        if (s[i] != t[j]) {
            puts("-1");
            return 0;
        }
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok?"Yes":"No");
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int N,Q;
vi to[200006];
ll add[200005];
ll ans[200005];

void dfs(int v=0, int p=-1, ll now=0) {
  now += add[v];
  ans[v] += now;
  for (int u: to[v]) {
    if (u==p) continue;
    dfs(u, v, now);
  }
}

int main() {
  cin >> N >> Q;
  rep(i,N-1) {
  int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,Q) {
    int p,x;cin>>p>>x;
    p--;
    add[p]+=x;
  }
  dfs();  
  rep(i,N) printf("%lld%c",ans[i],i==N-1?'\n':' ');
  return 0;
}

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

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }

        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char s[101];
int n,pos,maxn;
int main()
{
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='I')pos++;
        else --pos;
        maxn=max(maxn,pos);
    }
    printf("%d\n",maxn);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 N;
    cin >> N;

    int tmp = N;
    int S = 0;
    while (tmp > 0) {
        S += tmp % 10;
        tmp /= 10;
    }
    if (N % S == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

}



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

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL9_MOD = 1000000009;
static constexpr ll LL7_MOD = 1000000007;
static constexpr ll INF = 1LL << 60;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {
  { typeid(int), "%d" }, { typeid(ll), "%lld" }, { typeid(double), "%lf" }, { typeid(char), "%c" }};

template <class T> static void scan(vector<T>& v);
static void scan(vector<string>& v, bool isWord = true);
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val);
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; }
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val){ std::fill((T*)arr, (T*)(arr + N), val); }

ll dp[3001][3001];

int main(int argc, char *argv[]) {
  //INFILE();

  string s, t;
  cin >> s >> t;

  ll sl = s.size(), tl = t.size();

  REP(i, 1, sl + 1) {
    REP(j, 1, tl + 1) {
      chmax(dp[i][j], dp[i][j - 1]);
      chmax(dp[i][j], dp[i - 1][j]);
      chmax(dp[i][j], dp[i - 1][j - 1] + ll(s[i - 1] == t[j - 1]));
    }
  }

  string result;
  while (dp[sl][tl] != 0) {
    if (s[sl - 1] == t[tl - 1] && dp[sl - 1][tl - 1] == dp[sl][tl] - 1) {
      result.push_back(s[sl - 1]);
      sl--;
      tl--;
      continue;
    }

    if (dp[sl - 1][tl] == dp[sl][tl]) {
      sl--;
      continue;
    }

    tl--;
  }

  reverse(ALL(result));
  cout << result << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}



Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

static const int N=101;
static const int W=10010;
int dp[N+1];

int main(){
    int n;
    cin>>n;
    dp[0]=dp[1]=1;
    for(int i=2;i<=n;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout<<dp[n]<<endl;
  return 0;
}



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

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

    int count = 0;
    bool finished = false;

    while (!(finished)) {
        bool all = true;
        vector<bool> zero(N, false);
        for (int i = 0; i < N; i++) {
            if (h[i] == 0) {
                zero[i] = true;
            }

            else if (h[i] > 0) {
                h[i] --;
                if (i != N-1 && h[i+1] == 0) {
                    count ++;
                }
                if (i == N-1) {
                    count ++;
                }
            }    
        }
        for (int i = 0; i < N; i++) {
            if (zero[i] == false) all = false;
        }
        if (all) finished = true;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, p[5003] = {}, d[5003] = {};
    ll c[5003] = {}, e[5003] = {}, s = 0, z = -mod;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) cin >> c[i];
    for (int i = 1; i <= n; i++) {
        int b = p[i];
        d[i] = 1;
        e[i] = c[i];
        while (b != i) e[i] += c[b], b = p[b], d[i]++;
    }
    for (int i = 1; i <= n; i++) {
        if (e[i] < 0) {
            ll t = 0;
            int b = i;
            for (int j = 1; j <= min(d[i], k); j++) t += c[b], z = max(z, t), b = p[b];
        } else {
            ll t = 0;
            int b = i;
            for (int j = 1; j <= d[i]; j++) {
                t += c[b];
                if (j <= k % d[i]) z = max(z, t + e[i] * (k / d[i]));
                else z = max(z, t + e[i] * (k / d[i] - 1));
                b = p[b];
            }
        }
    }
    cout << z;
}


Measured memory_bytes: 3188
n = int(input())
A = [int(a) for a in input().split()]

num_negative = sum(a < 0 for a in A)
A_abs = [abs(a) for a in A]

if num_negative % 2 == 0:
    result = sum(A_abs)
else:
    result = sum(A_abs) - 2 * min(A_abs)

print(result)



Measured memory_bytes: 14412
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];

			var n = (int)Math.Ceiling(Math.Sqrt(N));

			var x = 0;

			for (int i = n; i > 0; i--) {

				if (N % i == 0) {
					x = i;
					break;
				}
			}
			var y = N / x;

			//答えの出力
			var ans = (x-1)+(y-1);
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 13396
#include<cstdio>

using namespace std;

int main(){
	int a, b; scanf("%d %d", &a, &b);
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) puts("Possible");
	else puts("Impossible");
	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

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

template< typename T >
map<T,int> prime_factorization(T n) {
	map<T,int> res;
	for(T i=2;i*i<=n;i++) {
		while(n%i==0) {
			res[i]++;
			n/=i;
		}
	}
	if(n!=1) res[n]=1;
	return res;
}

vector<bool> eratosthenes(int n) {
	vector<bool> is_prime(n+1,true);
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i*i<=n;i++) {
		if(is_prime[i]) {
			for(int j=2*i;j<=n;j+=i) {
				is_prime[j]=false;
			}
		}
	}
	return is_prime;
}

vector<int> prime_list(int n) {
	vector<int> res;
	auto is_prime=eratosthenes(n);
	for(int i=0;i<=n;i++) {
		if(is_prime[i]) {
			res.push_back(i);
		}
	}
	return res;
}

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

	ll n;cin>>n;
	auto ls=prime_factorization(n);
	cout<<n<<':';
	for(auto x:ls) {
		REP(i,x.se) cout<<' '<<x.fi;
	}
	cout<<endl;

}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;

int n, m;
char out[1002][1002];
long long dp[1002][1002];

int recurs(char out1[][1002], int i, int j){
	if(i==n-1 && j==m-1)
		return 1;
	if(i>=n || j>=m)
		return 0;
	if(out1[i][j] == '#')
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	dp[i][j] = (recurs(out1, i+1, j)+recurs(out1, i, j+1))%MOD;
	return dp[i][j];
}



int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
memset(dp, -1, sizeof(dp));
cin >> n >> m;
for(int i=0;i<n;i++){
	for(int j=0;j<m; j++){
		cin >> out[i][j];
	}
}
cout << recurs(out, 0, 0);
return 0;
}



Measured memory_bytes: 9216
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;



int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<ll> a(n),b(n+1);
    rep(i,n) cin >> a[i];
    rep(i,n) b[i+1]+=b[i]+a[i];
    ll ans=1e18;
    repr(i,1,n) {
        ans=(ans<abs((b[n]-b[i])-(b[i]-b[0])))?ans:abs((b[n]-b[i])-(b[i]-b[0]));
    }
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int k,s;
    cin >> k >> s;
    int x,y,z;
    int ans = 0;
    for(int i=0;i<=k;i++) {
        x = i;
        for(int j=0;j<=k;j++) {
            y = j;
            z = s-x-y;
            if (z>=0 && z<=k) ans++;
            /*for(int l=0; l<=k;l++) {
                z=l;
                if (x+y+z==s) ans++;
            }*/
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
#include<set>
#include<vector>
using namespace std;
int main(){

    string s;
    cin>>s;

    int mi=100000000;
    for(int i=0;i<s.size()-2;i++){
        int k=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');

        int ans=abs(k-753);
        mi=min(mi,ans);
        
        
    }
    cout<<mi<<endl;
    





return 0;
}


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

struct CWW{
    CWW(){
        cin.tie(0);
        ios_base::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    }
}STAR;

using D=double;

const D EPS=1e-8;
const D INF=1e9;

const int COUNTER_CLOCKWISE=1;
const int CLOCKWISE=-1;
const int ONLINE_FRONT=2;
const int ONLINE_BACK=-2;
const int ON_SEGMENT=0;

using Point=complex<D>;

struct Segment{
    Point p1,p2;
    Segment(const Point &p1=Point(),const Point &p2=Point()):p1(p1),p2(p2){}
};

struct Line{
    Point p1,p2;
    Line(const Point &p1=Point(),const Point &p2=Point()):p1(p1),p2(p2){}
};

struct Circle{
    Point c;
    D r;
    Circle(const Point &c=Point(),const D &r=0.0):c(c),r(r){}
};

using Polygon=vector<Point>;

istream& operator>>(istream &is,Point &a){
    D x,y;
    is>>x>>y;
    a=Point(x,y);
    return is;
}

ostream& operator<<(ostream& os,const Point &a){
    os<<real(a)<<" "<<imag(a);
    return os;
}

istream& operator>>(istream &is,Line &l){
    Point p1,p2;
    is>>p1>>p2;
    l=Line(p1,p2);
    return is;
}



D dot(const Point &a,const Point &b){
    return real(a)*real(b)+imag(a)*imag(b);
}

D cross(const Point &a,const Point &b){
    return real(a)*imag(b)-imag(a)*real(b);
}

Point projection(const Point &a,const Point &b){
    return a*real(b/a);
}

Point projection(const Line &l,const Point &a){
    return l.p1+projection(l.p2-l.p1,a-l.p1);
}

Point reflection(const Line &l,const Point &a){
    Point p=projection(l,a);
    return 2.0*p-a;
}

int ccw(Point a,Point b,Point c){
    b-=a;c-=a;
    if(cross(b,c)>EPS)return COUNTER_CLOCKWISE;
    if(cross(b,c)<-EPS)return CLOCKWISE;
    if(dot(b,c)<-EPS)return ONLINE_BACK;
    if(norm(b)+EPS<norm(c))return ONLINE_FRONT;
    return ON_SEGMENT;
}

int main(){
    Point a,b;
    cin>>a>>b;

    int Q;cin>>Q;
    while(Q--){
        Point c;
        cin>>c;

        int tmp=ccw(a,b,c);

        if(tmp==COUNTER_CLOCKWISE)cout<<"COUNTER_CLOCKWISE"<<endl;
        if(tmp==CLOCKWISE)cout<<"CLOCKWISE"<<endl;
        if(tmp==ONLINE_BACK)cout<<"ONLINE_BACK"<<endl;
        if(tmp==ONLINE_FRONT)cout<<"ONLINE_FRONT"<<endl;
        if(tmp==ON_SEGMENT)cout<<"ON_SEGMENT"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main() {
	
	int N = 0; //場所の個数
	scanf("%d",&N);
	
	int T = 0, A = 0; //平均気温と欲しい気温
	scanf("%d %d",&T, &A);
	
	float result = 10000;
	int res_num = 0;
	
	for( int i = 0; i < N; i ++){
		int H = 0; //その地点での標高
		scanf("%d", &H);
		
		float ondo = T - (float)H*0.006;
		
		float a_2 = A - ondo;
		
		if (a_2 < 0){
			a_2 = a_2 * -1;
		}
		
		if (a_2 < result){
			result = a_2;
			res_num = i + 1;
		}
		
	}
	
	printf("%d",res_num);
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#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()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

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

    int N, K;
    cin >> N >> K;
    vector<ll> d(N);
    rep(i, N) { cin >> d[i]; }

    ll ans = 0;

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            // 左からi個、右からj個。　
            if (i + j > N)
                continue;
            if (i + j > K)
                continue;
            int nokori = K - i - j;
            deque<ll> v;
            for (int k = 0; k < i; k++) {
                v.push_back(d[k]);
            }

            for (int l = N - 1; l > N - 1 - j; l--) {
                v.push_back(d[l]);
            }

            sort(all(v));
            while (!v.empty() && v.front() < 0 && nokori > 0) {
                v.pop_front();
                nokori--;
            }

            ll tmp = accumulate(all(v), (ll)0);
            ans = max(ans, tmp);
        }
    }

    cout << ans << endl;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    rep(i,s.size()) cout << 'x';
    cout << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAX_N (1000*100)
int N;
int H[MAX_N+5];

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> N;
	FOR(n,N) {
		cin >> H[n];
	}

	int ans = 0;
	int count = 0;
	FOR(n,N) {
		if(n==0) {
			continue;
		}
		if(H[n-1]>=H[n]) {
			count++;
		}
		else {
			ans = max(ans,count);
			count=0;
		}
	}
	ans = max(ans,count);

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 640
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sn=new Scanner(System.in);
		int n=sn.nextInt();
		int a=0;
		int cnt=0;
		int cnt4=0;
		int cnt2=0;
		do{
			a=sn.nextInt();
			if(a%4==0)
				cnt4++;
			else if(a%2==0)
				cnt2++;
			cnt++;
	}while(cnt<n);
	cnt4+=cnt2/2;
		if(cnt4>=n/2)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 50536
n = int(input())
t,a = map(int,input().split())
H = list(map(int,input().split()))
x = float('inf')
for i in range(len(H)):
    tmp = t - H[i]*0.006
    tmp2 = abs(a-tmp)
    if tmp2 < x:
        ans = i+1
        x = tmp2

print (ans)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws NumberFormatException, IOException {
		int period = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in), 128).readLine());
		int val = 100;//壱百千円
		for (; 0 < period; period--) {
			val = val * 105 % 100 == 0 ? (int) (val * 1.05) : (int) (val * 1.05) + 1;
		}
		System.out.println(val * 1000);
	}
}

Measured memory_bytes: 16844
#include<bits/stdc++.h>
#include<algorithm>
using namespace std; 
#define int long long
#define float double
#define LMT 100000000000
#define int long long 
#define lp(i,n) for( i=0;i<n;i++)
const int N=101,M=100001;
int n,w[N],v[N],i,j,wt;
int dp[N][M];

int solve(int pos,int cw){
 if(cw > wt)return -LMT;
 if(pos >=n)return 0;
 if(dp[pos][cw]!=-1)return dp[pos][cw];
int ans=max(v[pos]+solve(pos+1,cw+w[pos]),solve(pos+1,cw));
dp[pos][cw]=ans;
return ans;
}


int32_t main(){
  #ifndef ONLINE_JUDGE 
  freopen("input.txt", "r", stdin); 
  freopen("output.txt", "w", stdout); 
 #endif
  cin>>n>>wt;
  memset(dp,-1,sizeof(dp));
  lp(i,n)cin>>w[i]>>v[i];
  cout<<solve(0,0)<<endl;;
} 

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int H,W; cin>>H>>W;
  int h,w; cin>>h>>w;
  cout << (H-h)*(W-w) << endl;
}

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


Measured memory_bytes: 256
S = list(input())
if len(S) % 2 == 0:
    S1 = S[:len(S)//2]
    S2 = S[len(S)//2:]
else:
    S1 = S[:len(S)//2]
    S2 = S[(len(S)//2 + 1):]

S2 = S2[::-1]
ans = 0
for i in range(len(S1)):
    if S1[i] != S2[i]:
        ans += 1
print(ans)


Measured memory_bytes: 3060
import java.util.*;
class Main{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args){
		while(true){
			int h=s.nextInt(),w=s.nextInt();
			if(h==0&&w==0)
				break;
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 34568
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
	int n,i;
	scanf("%d",&n);
	int a[n],x[n],y[n];
	double D1=0.0,D21=0.0,D2,D31=0.0,D3,D4=0.0;
	for(i=0;i<n;i++)
		scanf("%d",&x[i]);
	for(i=0;i<n;i++)
		scanf("%d",&y[i]);
	for(i=0;i<n;i++)
		a[i]=abs(x[i]-y[i]);
	for(i=0;i<n;i++)
        		D1=(double)D1+a[i];
	for(i=0;i<n;i++)
		D21=(double)D21+(pow(a[i],2));
		D2=sqrt(D21);
	for(i=0;i<n;i++)
		D31=(double)D31+(pow(a[i],3));
		D3=pow(D31,1.0/3.0);
	for(i=0;i<n;i++)
	    if(a[i]>D4) D4=a[i];
	printf("%f\n",D1);
	printf("%f\n",D2);
	printf("%f\n",D3);
	printf("%f\n",D4);
	return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>

int main()
{
    int a,b,c,d;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);

    if(a>b){
        printf("%d",b*c+(a-b)*d);
    }else{
        printf("%d",a*c);
    }
    return 0;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    string s,c,left,right;
    ll q,t,f;
    bool r=0;
    cin >> s >> q;
    rep(i,q){
        cin >> t;
        if(t==1) r = 1-r;
        else{
            cin >> f >> c;
            if(f==1){
                if(r==0) left+=c;
                else right+=c;
            }
            else{
                if(r==0) right+=c;
                else left+=c;
            }
        }
    }
    if(r==0){
        reverse(all(left));
        print(left << s << right);
    }else{
        reverse(all(right));
        reverse(all(s));
        print(right << s << left);
    }
    
    return 0;
}

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

int main (){
  string str;
  long long a=0,b=0,c=0;
  long long q=1;
  long long k = 1000000007;
  cin >> str;
  for(long long i=0;i<str.length();i++){
    if(str[i]=='?'){
      c = (3*c + b)%k;
      b = (3*b + a)%k;
      a = (3*a + q)%k;
      q = (q*3)%k;
    }else if(str[i]=='A'){
      a = (a + q)%k;
    }else if(str[i]=='B'){
      b = (b + a)%k;
    }else if(str[i]=='C'){
      c = (c + b)%k;
    }
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 512
import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def multiple(a, b):
    return a*b // euclid(a, b)

def lcm(nums):
        return functools.reduce(multiple, nums)

N = int(input())
A = list(map(int, input().split()))
NumLCM = lcm(A)
ans = 0
for i in range(len(A)):
    ans += NumLCM // A[i]

print(ans % (10**9+7))

Measured memory_bytes: 4708
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
	
	ll n,k;
	cin>>n>>k;
	ll temp=n/k;
	temp=n-temp*k;
	if(temp<k-temp){
	
		cout<<temp<<'\n';
		return 0;
	}
	cout<<k-temp<<'\n';
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  int n, k;
  cin >> n >> k;
  char f;
  for(int i = 1; i <= n; i ++ ){
    cin >> f;
    if(i == k)
      cout << char(f + 'a'-'A');
    else
      cout << f;
  }
  return 0;
}

Measured memory_bytes: 256
S=input()
kisuu={'R','U','D'}
guusuu={'L','U','D'}

res = True

# print(S[::2])
for c in S[::2]:
    res = res and c in kisuu

# print(S[1::2])
for c in S[1::2]:
    res = res and c in guusuu

print('Yes' if res else 'No')


Measured memory_bytes: 3060
#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;
const int INF (1<<30);

int main() {
  int N, M; cin >> N >> M;
  int sumAC = 0;
  int sumWA = 0;
  vector<int> x(N, 0);

  rep(i, M) {
    int p;
    string s;
    cin >> p >> s;
    p--;

    if (s == "AC") {
      if (x[p] == -1) {
        continue;
      }
      else {
        sumAC++;
        sumWA += x[p];
        x[p] = -1;
      }
    }
    else {
      if (x[p] == -1) {
        continue;
      }
      else {
        x[p]++;
      }
    }
  }

  cout << sumAC << " " << sumWA;


  return 0;
}


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

int main(){
  int i, n, x, min = 2000;
  cin >> n >> x;

  int m[n];
  for( i=0; i<n; i++ ){
    cin >> m[i];
	x -= m[i];
    if( m[i] < min ){
      min = m[i];
    }
  }    
  cout << n+x/min << endl;
  return 0;
}


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

int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<int> x(N), y(M);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> y[i];
	}

	if (!(X < Y)) {
		cout << "War" << endl;
		return 0;
	}

	int x_max = -101;
	int y_min = 101;
	x_max = *max_element(x.begin(), x.end());
	y_min = *min_element(y.begin(), y.end());

	for (int i = X + 1; i <= Y; i++) {
		if (x_max < i && i <= y_min) {
			cout << "No War" << endl;
			return 0;
		}
	}

	cout << "War" << endl;


	return 0;
}

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

#define N 100001
int n, dp[N][4];

signed main() {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
                int val[4];
                scanf("%d%d%d", &val[1], &val[2], &val[3]);

                for (int j = 1; j <= 3; j++)
                        for (int k = 1; k <= 3; k++)
                                if (j != k)
                                        dp[i][k] = max(dp[i][k], dp[i-1][j] + val[k]);
        }
        printf("%d \n", max(dp[n][1], max(dp[n][2], dp[n][3])));

        return 0;
}


Measured memory_bytes: 1792
typedef int ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    ll N;
    string w[100];
    std::cin >> N;
    for (int i = 0; i < N; i++) {
        cin >>w[i];
    }
    for (int i = 0; i < N-1; i++) {
        if(w[i][w[i].length()-1]!=w[i+1][0]){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    sort(w,w+N);
    for (int i = 0; i < N-1; i++) {
        if(w[i]==w[i+1]){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

int main(){
	int n;
	string s;
	while (cin >> n >> s, n){
		int len = s.size();
		int ans = 0;
		vector<vector<int>> div;
		rep(i, 1 << (len - 1)){
			vector<int> v;
			int x = 0;
			int sum = 0;
			rep(j, len){
				if (j && (i&(1 << j - 1))){
					v.push_back(x);
					sum += x;
					x = 0;
				}
				x = x * 10 + s[j] - '0';
			}
			v.push_back(x);
			sum += x;

			if (sum <= n){
				if (ans < sum){
					div.clear();
					ans = sum;
				}
				if (ans == sum){
					div.push_back(v);
				}
			}
		}

		if (div.size() == 0){
			cout << "error" << endl;
		}
		else if (div.size() == 1){
			cout << ans;
			for (auto e : div[0]){
				cout << ' ' << e;
			}
			cout << endl;
		}
		else{
			cout << "rejected" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1224
from itertools import permutations
N, M, R = map(int, input().split())

# ワーシャフロイドで全点の最短経路を求める
# 訪問順を全列挙して全て試して、最も短いものが答えになる
# 計算量はワーシャルフロイドで200**3、全列挙で8!(40320)
# ワーシャルフロイドが間に合えばいけそう

r = list(map(lambda x: int(x)-1, input().split()))
edge = [[10**9] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    edge[a][b] = c
    edge[b][a] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j])
    
#print(edge)
ans = 10 ** 20
for per in permutations(r):
    tmp = 0
    for i in range(R-1):
        tmp += edge[per[i]][per[i+1]]
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 46936