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

namespace IO
{
char gc()
{
#ifdef FREAD
	static char buf[1<<21], *P1 = buf, *P2 = buf;
	if(P1 == P2)
	{
		P1 = buf;
		P2 = buf + fread(buf, 1, 1<<21, stdin);
		if(P1 == P2) return EOF;
	}
	return *(P1++);
#else
	return getchar();
#endif
}
template<typename Tp> bool get1(Tp &x)
{
	bool neg = 0;
	char c = gc();
	while( c != EOF && (c < '0' || c > '9') && c != '-' ) c = gc();
	if(c == '-') c = gc(), neg = 1;
	if(c == EOF) return false;
	x = 0;
	for(; c>='0' && c<='9'; c = gc()) x = x*10 + c - '0';
	if(neg) x = -x;
	return true;
}
template<typename Tp> void printendl(Tp x)
{
	if(x<0)putchar('-'),x=-x;
	static short a[40], sz;
	sz = 0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
	puts("");
}
} // namespace IO
using IO::get1;
using IO::printendl;
#define get2(x,y) get1(x) && get1(y)
#define get3(x,y,z) get2(x,y) && get1(z)
#define get4(x,y,z,w) get3(x,y,z) && get1(w)
#define pb push_back
#define mp std::make_pair
#define ff first
#define ss second
typedef long long LL;
typedef unsigned long long uLL;
typedef std::pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll<<61;

const int maxn = 311;
const int mod = 998244353;
inline void add(int &x, int y) { x += y; if(x >= mod) x -= mod; }

char s[maxn];
int n, dp[maxn][maxn][maxn];
bool can[maxn][maxn][maxn];

int main()
{
	scanf("%s", s);
	n = strlen(s);
	
	can[0][0][0] = 1;
	for(int k=0; k<n; k++)
	{
		for(int i=0; i<=n; i++) for(int k0=0; k0<=n; k0++)
		{
			int k1 = i - k - k0;
			if(k1 < 0) continue;
			if(!can[i][k0][k1]) continue;
			if(k0 && k0 + k1 >= 2) can[i][k0-1][k1] = 1;
			if(k1 && k0 + k1 >= 2) can[i][k0][k1-1] = 1;
			if(i < n)
			{
				if(k0 || k1) can[i+1][k0][k1] = 1;
				int p = s[i] - '0';
				if(p == 0 && k1) can[i+1][k0+1][k1-1] = 1;
				if(p == 1 && k0) can[i+1][k0-1][k1+1] = 1;
				if(i < n - 1)
				{
					int q = s[i+1] - '0';
					if(p == 0 || q == 0) can[i+2][k0+1][k1] = 1;
					if(p == 1 || q == 1) can[i+2][k0][k1+1] = 1;
				}
			}
		}
	}
	
	dp[0][0][0] = 1;
	for(int i=0; i<=n; i++) for(int n0=0; n0<=n; n0++) for(int n1=0; n1<=n; n1++) if(dp[i][n0][n1])
	{
		int pos = s[n - 1 - (i - n0 - n1)] - '0';
		
		add(dp[i+1][n0][n1], dp[i][n0][n1]);
		if(pos == 0) add(dp[i+1][n0][n1+1], dp[i][n0][n1]);
		else add(dp[i+1][n0+1][n1], dp[i][n0][n1]);
	}
	
	for(int i=n-1; i>=0; i--) for(int k0=0; k0<=n; k0++) for(int k1=0; k1<=n; k1++)
	{
		if(can[i+1][k0][k1])
		{
			int p = s[i] - '0';
			if(p == 0 && k0) can[i][k0-1][k1] = 1;
			if(p == 1 && k1) can[i][k0][k1-1] = 1;
		}
	}
	
	int ans = 0;
	for(int i=1; i<=n; i++) for(int j=0; j<=n; j++) for(int k=0; k<=n; k++) if(dp[i][j][k])
	{
		int pos = n - (i - j - k);
		if(can[pos][j][k]) add(ans, dp[i][j][k]);
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 68116
#include<iostream>

using namespace std;

int dfs(int n, int dan){

	if(dan == n){
		return 1;
	}
	else if(dan > n){
		return 0;
	}
	else{
		int count = 0;
		count = count + dfs(n, dan + 1);
		count = count + dfs(n, dan + 2);
		count = count + dfs(n, dan + 3);
		return count;
	}
}

int main(){
	
	int n;

	while(1){
		cin>>n;

		if(n == 0) break;

		cout<<dfs(n,0) / 10 / 365 + 1<<endl;
	}
}

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

int main()
{
	int X, Y;
	cin >> X >> Y;
	int at = X * 2;
	int ak = X * 4;
	if (ak < Y || at > Y) {
		cout << "No";
	}
	else {
		cout << (((ak - Y) % 2 == 0) ? "Yes" : "No");
	}

	return 0;
}


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

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

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

inline void proc_status()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl;
}

template <typename T> T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int Maxn = 1e5 + 100, Maxk = 100 + 10;

int N, K, A[Maxn], Dp[Maxn];

inline void Solve ()
{
	memset(Dp, 0x3f, sizeof Dp);
	Dp[1] = 0;
	for (int i = 1; i <= N; ++i)
	{
		for (int j = 1; j <= K; ++j)
			Chkmin(Dp[i + j], Dp[i] + abs(A[i + j] - A[i]));
	}
	cout<<Dp[N]<<endl;
}

inline void Input ()
{
	N = read<int>(), K = read<int>();
	for (int i = 1; i <= N; ++i) A[i] = read<int>();
}

int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}


Measured memory_bytes: 1024
# ans

N = int(input())

ans = [0] * (N + 1)
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      n = x * x + y * y + z * z + x * y + y * z + z * x
      if n <= N:
        ans[n] += 1

for i in range(1, len(ans)):
  print(ans[i])

Measured memory_bytes: 74724
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,k,a[100005],ans=0,mi,b[100005],x,y,z;
int main()
{
	mi=200000;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),mi=min(mi,a[i]);
	ans+=mi;
	mi=200000;
	for(int i=1;i<=m;i++)scanf("%d",&b[i]),mi=min(mi,b[i]);
	ans+=mi;
	for(int i=1;i<=k;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		ans=min(ans,a[x]+b[y]-z);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn divisors(n: u64) -> Vec<u64> {
    let mut m = 1;
    let mut divs = vec![];
    while m * m <= n {
        if n % m == 0 {
            divs.push(m);
            if n != m * m {
                divs.push(n / m);
            }
        }
        m += 1;
    }
    divs.sort();
    divs
}

fn main() {
    input! {
        n: u64,
    }
    let mut divs = divisors(n);
    if divs.len() % 2 == 0 {
        let idx = divs.len() / 2 -1;
        println!("{}", divs[idx]+ divs[idx+1]-2);
    } else {
        let idx = divs.len() / 2;
        println!("{}", divs[idx] * 2 - 2);
    }
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) throws IOException {
        init(System.in);
        int[] abc = new int[3];
        for (int i = 0; i < abc.length; i++) abc[i] = nextInt();
        Arrays.sort(abc);
        int diff1 = abc[2] - abc[0];
        int diff2 = abc[2] - abc[1];
        if (diff1 % 2 == 0 && diff2 % 2 == 0) System.out.println(diff1/2 + diff2/2);
        else if (diff1 % 2 == 1 && diff2 % 2 == 0) System.out.println(1 + diff2/2 + (diff1 + 1)/2);
        else if (diff1 % 2 == 0 && diff2 % 2 == 1) System.out.println(1 + diff1/2 + (diff2 + 1)/2);
        else System.out.println(1 + (diff1 - 1)/2 + (diff2 - 1)/2);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

//    private static long nextLong() throws IOException {
//        return Long.parseLong(next());
//    }
//
//    //    Get a whole line.
//    private static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    private static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}

Measured memory_bytes: 22612
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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(b<a){a=b;return 1;}return 0;}

void solve();

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

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

    cout<<s.substr(0,3)<<endl;
}


Measured memory_bytes: 3636
n,m,k=map(int,input().split())
M=10**9+7
c=1
a=0
for i in range(1,k-1):c=(c*(n*m-1-i)*pow(i,M-2,M))%M
for i in range(n):a=(a+i*(n-i)*(m**2)*c)%M
for i in range(m):a=(a+i*(m-i)*(n**2)*c)%M
print(a)

Measured memory_bytes: 3064
K = int(input())

def dfs(d, val, x):
    x.append(val)
    
    if d == 10:
        return
    
    for i in range(-1, 2):
        add = (val % 10) + i
        if 0 <= add <= 9:
            dfs(d + 1, val * 10 + add, x)

x = []
for i in range(1, 10):
    dfs(0, i, x)
print(sorted(x)[K - 1])


Measured memory_bytes: 100856
#include <bits/stdc++.h>
using namespace std;
long long a, b, x;
long long f;

long long func(long long n) {
    if(n >= 0) {
        return f = n/x + 1;
    }else {
        return f = 0;
    }
}
int main() {
    cin >> a >> b >> x;
    long long cnt = 0;
    
    cnt = func(b) - func(a-1);

    cout << cnt << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string t;
    cin >> t;
    rep (i, 7) {
        if (s[i] == t) {
            cout << 7 - i << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, T = map(int, input().split())
    ans = 10000
    for _ in range(n):
        c, t = map(int, input().split())
        if t <= T:
            ans = min(ans, c)
    print(ans if ans <= 1000 else 'TLE')
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 62168
# -*-coding:utf-8

lineNum = int(input())

for i in range(lineNum):
    line = input()
    tokens = list(map(int, line.strip().split()))

    tokens.sort()

    a, b, c = tokens[0], tokens[1], tokens[2]

    if pow(a,2)+pow(b,2) == pow(c,2):
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 7576
/*
                   _ooOoo_
                  o8888888o
                  88" . "88　AC!AC!
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
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 (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
const int N = pow(10,6);

vector<bool> isp(N+1, true);

void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=N; i++) {
    if (isp[i]) for(int j=2; i*j<=N; j++) isp[i*j] = false;
  }
}
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
   	V vec;
   	int n;cin>>n;
   	sieve();
   	rep3(i,2,55555){
   	    if(isp[i]&&i%5==1){
   	        vec.push_back(i);
   	    }
   	}
   	rep(i,n)cout<<vec[i]<<" ";
   	cout<<endl;
}
    


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;

ll C2(ll a){
    if(a<2) return 0;
    else return a*(a-1)/2;
}



int main(int argc, const char * argv[]) {
    
 

    cin.tie(0);
    ios::sync_with_stdio(false);
   
    map<string,ll> anagram{};
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        sort(s.begin(), s.end());
        if(!anagram.count(s)) anagram.insert(make_pair(s,1));
        else anagram[s]++;
    }
    
    ll Ans = 0;
    for(auto it = anagram.begin(); it != anagram.end(); it++){
        Ans += C2((*it).second);
    }
    
    cout << Ans << endl;
    
    
    
    
    
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n,k;
    cin>>n>>k;
    vector<double> v(n+1);
    double ans=0;
    double sum =0;
    rep(i,n) {
       double p;
       cin>>p;
       sum+=(p+1)/2;
       v[i+1]=sum;
    }
    for(int i=0;i<n-k+1;i++){
        ans=max(ans,v[i+k] -v[i]);
    }
    printf("%12f\n",ans);
}

Measured memory_bytes: 1792
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a1 = na()
a2 = na()
a3 = na()

A = a1+a2+a3
C = [0,0,0,0,0,0,0,0,0]

n = ni()

for i in range(n):
    b = ni()
    if b in A:
        C[A.index(b)] = 1
    if sum(C[0:3]) == 3 or sum(C[3:6])==3 or sum(C[6:9]) == 3 or sum(C[::4]) == 3 or sum(C[2:7:2]) == 3 or sum(C[0::3]) == 3 or sum(C[1::3]) == 3 or sum(C[2::3]) == 3:
        print('Yes')
        exit()

print("No")

Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("in","r", stdin);
		freopen("out","w",stdout);
	#endif

	int n;
	cin>>n;
	int u,v;

	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=i*(n-i+1);
	}

	//edges
	for(int i=1;i<n;i++)
	{
		cin>>u>>v;
		if(u>v)swap(u,v);
		int sub=(n-v+1)*u;
		ans-=sub;
	}
	cout<<ans;


}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int mod=(1e9)+7;
int n,m;
int a[2010],b[2010];
ll dp[2010][2010];
ll s[2010][2010],ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m);
	for (int i=1;i<=n;i++) read(a[i]);
	for (int j=1;j<=m;j++) read(b[j]);
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=m;j++) {
			if (a[i]==b[j]) {
				dp[i][j]=s[i-1][j-1]+1;
				dp[i][j]=(dp[i][j]%mod+mod)%mod;
				ans=(ans+dp[i][j])%mod;
			}	
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+dp[i][j];
			s[i][j]=(s[i][j]%mod+mod)%mod;
		}
	}
	printf("%lld\n",(ans+1)%mod);
	return 0;
}

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

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

	if(a>b+w){cout<<a-(b+w); return 0;}
	if(a+w<b){cout<<b-(a+w); return 0;}
	else cout<<0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n";
long long M = 1e9+7;
long long power(long long a, long long p)
{
    if(p==0) return 1;
    long long ans= power(a,p/2);
    ans =(ans * ans) % M;
    if(p%2) ans = (ans*a) % M;
    return ans;
}

bool isPrime(long long n)
{
    if (n <= 1)
        return false;
    for (long long i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}
long long SieveOfEratosthenes(long long n, long long a)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (long long p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (long long p=2; p<=n; p++)
       if (prime[p])
       {
           if(a%p==0)
           {
               return (a-p);
           }
       }
}
long long nCr(int n, int r)
{
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }
    return ans;
}
//int vis[51][51];
//int x[]={1,0,0,-1};
//int y[]={0,1,-1,0};
/* void dfs_visit(long long n,long long a, long long b)
{
    vis[a][b]=1;
    for(int i=0; i<4; i++)
    {

        int p=a+x[i];
        int q=b+y[i];
        if(p>=0 && p<n && q>=0 && q<n && vis[p][q]==0)
        {
           // cout<<p<<" "<<q<<endl;
            vis[p][q]=1;
            dfs_visit(n,p,q);
        }
    }
}
*/
long long fun(long long a)
{
    long long co=1,res=0;
    while(a>0)
    {
        if(a%2==0)
        {
            res=co;
        }
        a/=2;
        co++;
    }
    return res;
}

int main()
{
    IOS;
    long long a,b,c,d,e,h,l,n,t,f,m,f1=0,flag=0,flag1=0,co=0,co1=0,co2=0,arr1[100001]={0},sum=0,sum1=0,ma=0,ma1=0,mi=1000000000000000001;
    long long g,co3=0,co4=0,co5=0,co6=0,co7=0,co8=0,mul=1,sum2=0,sum3=0,mu=1,mu1=1;
    long long a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,b6;
    double pi=2 * acos (0.0);
    string str,str1,str2,str3,str4,str5,str6;
    char ch,ch1;
    //vector<long long>v; //vector<long long> v(n+1);
    //vector<long long>v1;
   // vector<string>vs;
   // vector<string>vs1;
    //map<long long,long long>mp;
    //set<long long>s;
    //stack<long long> stk;
    //vector< pair<long long,long long> >v3;
    //map<long long,long long>::iterator it;
    //map<string,string>::iterator it;
   // vector<pair<char, pair<int,int> > > v3;
    //vector< pair<char,int > > v1;
    //int x[]={1,1,1,0,0,-1,-1,-1};
    //int y[]={0,1,-1,1,-1,1,-1,0};
    //int x[]={1,0,0,-1};
    //int y[]={0,1,-1,0};
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            for(int k=1; k<=n; k++)
            {
                sum+=(__gcd(i,__gcd(j,k)));
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 924844033;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	string s, t; cin >> s >> t;
	int l = s.length();
	int l2 = t.length();
	int ma = 0;
	rep(i, l) {
		string u = s.substr(i, l - i);
		if (l - i <= l2) {
			string us = t.substr(0, l - i);
			if (u == us)ma = max(ma, l - i);
		}
	}
	cout << l + l2 - ma << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,i,j,a,sum;
  sum=0;
  j=10000;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a;
    while(a%2==0){
      sum++;
      a=a/2;
    }
    if(sum<j){
      j=sum;
    }
    sum=0;
  }  
  cout<<j<<endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.bitmanip;

final class PrimeTable {
  private:
  BitArray a;
  size_t n;
  public:
  pure nothrow @nogc
  bool isPrime (size_t i) const {
    return (i & 1) ? !a[i>>>1] : (i == 2);
  }
  pure
  this (size_t _n) {
    n = _n;
    auto m = n >> 1;
    a.length = max (1, m);
    a[0] = true;
    foreach (i; 1 .. ceil((sqrt (n.to!(double)) - 1.0)).to!(size_t)) {
      if (!a[i]) {
        immutable k = (i << 1) + 1;
        for (size_t j = 2 * i * (i + 1); j < m; j += k) {
          a[j] = true;
        }
      }
    }
  }
}


void main() {
  int x;
  readf (" %d", &x);
  auto pt = new PrimeTable (x + 100000);
  while (!pt.isPrime(x)) ++x;
  writeln (x);
}



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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    vector<int> A(N);
    for ( int i = 0; i < N; i++ ) cin >> A.at(i);

    sort(A.begin(), A.end(), greater<int>());

    long long ans = 0;
    queue<int> q;
    q.push(A.at(0));

    for ( int i = 1; i < N; i++ ) {
        ans += q.front(); q.pop();
        q.push(A.at(i));
        q.push(A.at(i));
    }

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


Measured memory_bytes: 4840
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  long long a;
  int digits[10];
  int len = 0;
  int i;
  int min = 1e9;
  
  scanf("%lld",&a);

  while(a>0) {
    digits[len] = a%10;
    a /= 10;
    len++;
  }
  
  for(i=0;i<len-2;i++) {
    a = 100*digits[len-1-i] + 10*digits[len-2-i] + digits[len-3-i];
    if(abs(a-753)<min) min=abs(a-753);
  }

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


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;



int main(void) {
    ll n,m;
    cin>>n>>m;
    vl pitsu(n+1);
    rep(i,m){
        ll l,r;
        cin>>l>>r;
        l--;
        pitsu[l]++;
        pitsu[r]--;
    }
    rep(i,n){
        //cout<<pitsu[i]<<endl;
        pitsu[i+1] += pitsu[i];
    }
    ll ans = 0;
    rep(i,n){
        if(pitsu[i] == m) ans++;
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3968
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int c1, c2, c3;
		int ans;
		
		while(scan.hasNextInt()){
			c1 = scan.nextInt();
			c2 = scan.nextInt();
			c3 = scan.nextInt();
			
			ans = 0;
			
			for(int i = 1; i <= 10; i++){
				if(i != c1 && i != c2 && i != c3){
					if(c1 + c2 + i <= 20)ans++;
				}
			}
			if(ans >= 4)System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 26304
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	long long n; cin >> n;
	vector<long long> hv;
	for(long long i = 0; i < n; i++){
		long long h; cin >> h;
		hv.push_back(h);
	}

	bool ok = true;

	// for(long long i = 0; i < n - 1; i++){
	// 	if(hv[i]-1 <= hv[i+1]){
	// 		if(hv[i]-1 == hv[i+1]){
	// 			hv[i]--;
	// 			if(i > 0 && hv[i-1] > hv[i]){
	// 				ok = false;
	// 				break;
	// 			}
	// 		}
	// 	}else {
	// 		ok = false;
	// 		break;
	// 	}
	for(int i = hv.size() - 1; i >= 1; i--){
		if(hv[i] < hv[i-1]){
			if(hv[i] == hv[i-1] - 1)hv[i-1]--;
			else ok = false;
		}
	}
	
	//}

	cout << ((ok) ?"Yes":"No") << endl;
}

Measured memory_bytes: 1528
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
using namespace std;

bool is_prime(int x) {
	for(int i = 2; i < floor(sqrt(x)); i++) {
		if(x % i == 0) return false;
	}
	return true;
}

int main () {
	int x; 
	cin >> x;
	for(long i = (long long) x; true; i++) {
		if(is_prime(i) == true) {
			cout << i << "\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<bool, int>> v;
    rep(i, n) v.push_back(make_pair(false, 0));
    rep(i,m){
        int p;
        string s;
        cin >> p >> s;
        if(s=="AC"){
            if(v[p-1].first==false)
                v[p - 1].first = true;
        }
        if(s=="WA"){
            if(v[p-1].first==false)
                v[p - 1].second++;
        }
    }
    int ac = 0, pena = 0;
    rep(i, n) {
        if(v[i].first==true){
            ac++;
            pena += v[i].second;
        }
    }
    cout << ac << " " << pena << endl;
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

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

	vector<string> S(N);

	for (int i = 0; i < S.size(); ++i) cin >> S[i];

	sort(ASC(S));

	for (int i = 0; i < S.size(); i++)
	{
		cout << S[i];
	}
}

Measured memory_bytes: 256
import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List as L

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO()
main = do
  [a, b, c] <- map read . words <$> getLine
  [k] <- map read . words <$> getLine
  printf "%d" $ slv a b c k

slv :: Integer -> Integer -> Integer -> Integer -> Integer
slv a b c k = sumabc - maximumabc + maximumabc * 2^k
  where sumabc = a + b + c
        maximumabc = maximum [a, b, c]

Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

int N, H;
int b[100000];

int updiv(int x, int y) {
	if (x%y == 0) return x / y;
	else return x / y + 1;
}

int main() {
	cin >> N >> H;
	int maxA = 0;
	for (int i = 0; i < N; i++) {
		int tmpA;
		cin >> tmpA >> b[i];
		maxA = max(maxA, tmpA);
	}

	sort(b, b + N, greater<int>());

	int ans = 0;
	for (int i = 0; i < N && H > 0 && b[i] >= maxA; i++) {
		H -= b[i];
		ans++;
	}

	if (H > 0) ans += updiv(H, maxA);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <stack>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double c = 1e5+5;
int main()
{	
	string s,t;
	cin>>s;
	int len =s.size();
	rep(i,0,len-8) t+=s[i];
	cout<<t<<endl;
	return 0;
}



Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0

for a in range(A + 1):
  if 500 * a <= X:
    for b in range(B + 1):
      if 500 * a + 100 * b <= X:
        for c in range(C + 1):
          if 500 * a + 100 * b + 50 * c == X:
            cnt += 1
print(cnt)

Measured memory_bytes: 9128
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;

struct node{
  node *p;
  node *r;
  node *l;
  int key;
};

node *root,*NIL;


void init(){
  NIL = (node *)malloc(sizeof(node));
  NIL->p = NIL;
  NIL->r = NIL;
  NIL->l = NIL;
  NIL->key = -1;
  root = (node *)malloc(sizeof(node));
  root = NIL;
  root->p = NIL;
  root->r = NIL;
  root->l = NIL;
  root->l->p = root->r->p = root;
}

void inorder(node *x){
  if(x == NIL) return;
  inorder(x->l);
  printf(" %d",x->key);
  inorder(x->r);
}

void preorder(node *x){
  if(x == NIL) return;
  printf(" %d",x->key);
  preorder(x->l);
  preorder(x->r);
}


void print(){
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}

void insert(int k){
  //cout << k << endl;
  node *z;
  z = (node *)malloc(sizeof(node));
  z->r = NIL;
  z->l = NIL;
  z->key = k;

  node *x,*y;
  x = root;
  y = NIL;
  //printf("x->key = %d\n",x->key);
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->l;
    else if(z->key > x->key) x = x->r;
    //printf("x->key1 = %d\n",x->key);
  }
  //printf("y->key = %d\n",y->key);
  if(y == NIL) root = z;
  else if(z->key < y->key) y->l = z;
  else if(z->key > y->key) y->r = z;

  z->p = y->p;
//  inorder(root);
  //printf("\n");
}


void find(int k){

  node *z;
  z = (node *)malloc(sizeof(node));
  z->key = k;
  z->r = NIL;
  z->l = NIL;

  node *x = root;
  while(1){
    if(z->key == x->key) {
      cout << "yes" << endl;
      return;
    }
    else if(x == NIL){
      cout << "no" << endl;
      return;
    }
    if(z->key < x->key) x = x->l;
    if(z->key > x->key) x = x->r;
  }
  //inorder(root);
  //printf("\n");
}


int main(){

  int m,k;
  string com;
  cin >> m;

  init();

  for(int i = 0;i < m;i++){
    cin >> com;
    if(com == "insert"){
      cin >> k;
      //cout << k << endl;
      insert(k);
    }
    else if(com == "find"){
      cin >> k;
      find (k);
    }
    else if(com == "print") print();
  }
}

Measured memory_bytes: 26608
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;
int gcd(int a, int b)
{
    if(b) return gcd(b,a%b);
    return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,m,a[1 << 18],t[1 << 21],lz[1 << 21];
vector<pair<int,int>>vec[1 << 18];
int ans;

void push(int nod)
{
	t[nod] += lz[nod];
	lz[nod << 1] += lz[nod];
	lz[nod << 1 | 1] += lz[nod];
	lz[nod] = 0;	
}

void upd(int nod,int tl,int tr,int l,int r,int val)
{
	if(l > r) return ;
	push(nod);
	if(tl == l && tr == r)
	{
		lz[nod] += val;
		push(nod);
		return ;
	}
	int mid = tl + tr >> 1;
	upd(nod << 1,tl,mid,l,min(mid,r),val);
	upd(nod << 1 | 1,mid + 1,tr,max(mid + 1,l),r,val);
	t[nod] = max(t[nod << 1] + lz[nod << 1],t[nod << 1 | 1] + lz[nod << 1 | 1]);
}

void upd2(int nod,int l,int r,int pos,int val)
{
	if(l == r){
		t[nod] = val;
		return ;
	}
	int mid = l + r >> 1;
	if(pos <= mid){
		upd2(nod << 1,l,mid,pos,val);
	}
	else upd2(nod << 1 | 1,mid + 1,r,pos,val);
	t[nod] = max(t[nod << 1],t[nod << 1 | 1]);
}

int qry(int nod,int tl,int tr,int l,int r)
{
	if(l > r) return -1e18;
	push(nod);
	if(l == tl && r == tr) return t[nod];
	int mid = tl + tr >> 1;
	return max(qry(nod << 1,tl,mid,l,min(mid,r)),
	qry(nod << 1 | 1,mid + 1,tr,max(mid + 1,l),r));
}

int32_t main(){_
    //freopen("in","r",stdin);
	cin >> n >> m;
	for(int i = 1;i <= 4 * n;i++) t[i] = -1e18;
	while(m--)
	{
		int x,y,z;
		cin >> x >> y >> z;
		a[x] += z;
		a[y + 1] -= z;
		vec[y + 1].pb(mp(x,z));
	}
	for(int i = 1;i <= n;i++)
	{
		a[i] += a[i - 1];
		for(auto it : vec[i])
		{
			upd(1,1,n,it.first,i - 1,it.second);
		}
		upd2(1,1,n,i,0);
		int x = a[i] + qry(1,1,n,1,i);
		ans = max(ans,x);
		upd2(1,1,n,i,x - a[i]);
	}
	rc(ans);
}

Measured memory_bytes: 33152
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    int h[100000];
    cin >> N;
    for(int i = 0; i < N; i++) cin >> h[i];
    int dp[100000];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i = 2; i < N; i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[N-1] << endl;
}

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

int main() {
  ll x;
  cin >> x;
  ll sum = 0;
  ll t = x;
  while(t > 0){
   sum +=  t % 10;
    t /= 10;
  }
  if(x % sum == 0){
    cout << "Yes" << endl;
  }
    else{
      cout << "No" << endl;
    }
  }


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main() {
    int N;
    cin >> N;
    double JPY = 0;
    double BTC = 0;
    for (size_t i = 0; i < N; i++)
    {
        string ccy;
        double temp;
        cin >> temp >> ccy;
        if (ccy == "JPY")
            JPY += temp;
        else
            BTC += temp;
    }
    double ret = JPY + 380000 * BTC;
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin

def main():
	a,b = [int(x) for x in stdin.readline().strip().split()]
	if a == 0 or b == 0 or ( a < 0 and b > 0):
		print("Zero")
	elif a > 0 and b > 0 or (a == b):
		print("Positive")
	else:
		val = abs(abs(b)-abs(a))
		if val%2 == 0 :
			print("Negative")
		else:
			print("Positive")
main()

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

int main() {
	int A=0, B;
	int N, K, x, sum=0;
	
	cin >> N >> K;
	
	B=K;
	
	for(int i=0; i<N; i++){
		int x, A2, B2;
		cin >> x;
		if(A<x){
			A2=x-A;
		}
		if(B<x){
			B2=x-B;
		} else {
			B2=B-x;
		}
		
		if(A2 > B2){
			sum+=2*B2;
		} else {
			sum+=2*A2;
		}
	}
	
	cout << sum << endl;
}

Measured memory_bytes: 256
a,b = gets.split(" ").map(&:to_s)
a = a.chomp
b = b.chomp

def hantei(h)
    if h == "H"
        return 1
    elsif h == "D"
        return -1
    end
end

a = hantei(a)
b = hantei(b)

if a*b == 1
    puts "H"
elsif a*b == -1
    puts "D"
end

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

int main()
{
	long long k, n;
	cin >> k >> n;

	vector<long long> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];

	vector<long long> b;
	b.clear();

	for (int i = 0; i < n - 1; ++i)
	{
		long long distance = 0;
		distance = a[i + 1] - a[i];
		b.emplace_back(distance);
	}

	b.emplace_back(a[0] + (k - a[n-1]));

	std::vector<long long>::iterator iter = std::max_element(b.begin(), b.end());
	size_t index = std::distance(b.begin(), iter);

	cout << (k - b[index]) << endl;

	return 0;
}


Measured memory_bytes: 4084
# ABC154 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,k=nm()
ans=0
p=nl()
# p=set(p)
# p=list(p)
# p.sort(reverse=True)
e=[0]*n

for i in range(n):
    e[i]=(p[i]*(p[i]+1))/(2*p[i])

s=sum(e[:k])

t=0
ans=0
for i in range(n-k+1):
    if i==0:
        t=s
        ans=max(ans,t)
        continue
    t+=e[i+k-1]
    t-=e[i-1]
    ans=max(ans,t)
print(ans)

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


#define ll          long long
#define uint        unsigned int 
#define ld          long double
#define SAM         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#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 mod         1000000007
#define mxn         200005
#define pb          push_back
#define pii         pair<int,int>
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define all(x)      x.begin(),x.end()

using namespace std;

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

int power(int a,int n)
{
    a %= mod;
    if(n == 1) return a;
    if(n == 0) return 1;
    if(n%2) return (a*(power((a*a)%mod,n/2)%mod))%mod;           //n is odd
    return power((a*a)%mod,n/2)%mod;                             //n is even
}

const int inf = (int) 1e18;

int inverse(int x)
{
    return power(x,mod-2)%mod;     //Fermat's little theorem
}*/

int main()
{
    SAM;
    int x;
    cin>>x;
    if(x==0)
        cout<<"1";
    else
        cout<<"0";
    
    return 0;
}




Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <functional>
#include <string.h>

using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

typedef pair<ll,int>P;
#define INF (1LL<<61)

int n;
vector<ll> a, sum;
 
int main(){
	scanf("%d ", &n);
	vector<ll> a(n);
	rep(i, n) {
		scanf("%lld ", &a[i]);
	}
	vector<int> idx;
	vector<ll> num;
	ll t = 0;
	//idx.push_back(0);
	//num.push_back(0);
	rep(i, n) {
		if (t < a[i]) {
			t = a[i];
			idx.push_back(i);
			num.push_back(a[i]);
		}
	}
	vector<ll> b = a;
	sort(all(b));
	vector<ll> sum = b;
	for (int i = n - 2; i >= 0; i--) {
		sum[i] += sum[i + 1];
	}
	map<int, ll> m;
	ll tmpsum = 0;
	for (int i = idx.size() - 2; i >= 0; i--) {
		int pos = lower_bound(all(b), num[i]) - b.begin();
		ll tmp=sum[pos] - b[pos] * (n - pos);
		m[idx[i+1]] = tmp - tmpsum;
		tmpsum += tmp - tmpsum;
	}
	m[idx[0]] = sum[0] - tmpsum;
	rep(i, n) {
		cout << m[i] << endl;
	}
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  bool flag = true;
  for(int i = 0; i < s.length() / 2; i++){
    if(s[i] != s[s.length()-i-1]) flag = false;
  }
  if(flag && s.length() == 5) {
    flag = false;
  }
  else if(flag && s.length() >= 7) {
    string firsthalf = s.substr(0, s.length()/2);
    string secondhalf = s.substr(s.length()/2+1, s.length()/2);
    for(int i = 0; i < firsthalf.length()/2; i++){
      if(firsthalf[i] != firsthalf[firsthalf.length()-i-1] || secondhalf[i] != secondhalf[secondhalf.length()-i-1]) flag = false;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,str,end) for(ll i=(ll)(str); i<(ll)(end); i++)

int main(){
    string a,b;
    cin>>a>>b;
    if(a==b){cout<<"EQUAL"<<endl;return 0;}
    else if(a.size()<b.size()){cout<<"LESS"<<endl;return 0;}
    else if(a.size()>b.size()){cout<<"GREATER"<<endl;return 0;}
    else if(a.size()==b.size()){
        rep(i, 0, a.size() ){
            int N=a[i]-'0';
            int M=b[i]-'0';
            if(N>M)
            {cout<<"GREATER"<<endl;return 0;}
            else if(N<M)
            {cout<<"LESS"<<endl;return 0;}
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define K 1000000007

using namespace std;
int main(){
	int n,m,i;
	cin >> n >> m;
	long long x[n],y[m],a=0,b=0;
	
	for(i=0;i<n;i++){
		cin >> x[i];
		x[i] = (x[i]+K)%K;
	}
	
	for(i=0;i<m;i++){
		cin >> y[i];
		y[i] = (y[i]+K)%K;
	}
	for(i=0;i<n;i++){
		a = a+(2*(i+1)-n-1+K)%K*x[i];
		a = (a+K)%K;
	}
	for(i=0;i<m;i++){
		b = b+(2*(i+1)-m-1+K)%K*y[i];
		b = (b+K)%K;
	}
	
	long long ans = a%K*b%K;
	
	cout << ans%K << endl;
}

Measured memory_bytes: 1792
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

string field[24];

void dfs(int y, int x)
{
  field[y][x] = '0';
  REP(i, 4){
    int ny = y + dy[i], nx = x + dx[i];
    if (!inside(nx, ny, 12, 12)) continue;
    if (field[ny][nx] != '1') continue;
    dfs(ny, nx);
  }
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (cin >> field[0]){
    int ans = 0;
    REP(i, 11){
      cin >> field[i + 1];
    }
    REP(i, 12){
      REP(j, 12){
        if (field[j][i] == '1'){
          dfs(j, i);
          ans++;
        }
      }
    }
    print(ans);
  }
  
  return (0);
}

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

int main()
{
    for (;;) {
        int x, y;
        cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        }
        if (x > y) {
            swap(x, y);
        }
        cout << x << " " << y << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
from fractions import gcd
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b,c = readInts()
    ab = abs(a-b)
    bc = abs(b-c)
    cnt = 0
    if a == b == c == 1:
        print(0)
        exit()
    if ab == 0 and bc == 0:
        print('-1')
        exit()
    while True:
        if ab % 2 == 0 and bc % 2 == 0:
            ab //= 2
            bc //= 2
            cnt += 1
        else:
            break
    print(cnt)

if __name__ == '__main__':
  main()


Measured memory_bytes: 5148
N = int(input())
AC, WA, TLE, RE = 0, 0, 0, 0
for i in range(N):
  temp = input()
  if temp == 'AC':
    AC += 1
  elif temp == 'WA':
    WA += 1
  elif temp == 'TLE':
    TLE += 1
  else:
    RE += 1

print('AC x', AC)
print('WA x', WA)
print('TLE x', TLE)
print('RE x', RE)

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

int main() {
  char c = 0;
  cin >> c ;
  switch (c) {
    case 'a':
    case 'i':
    case 'u':
    case 'e':
    case 'o':
      cout << "vowel" << endl;
      break;
    default:
      cout << "consonant" << endl;
  };
  
}


Measured memory_bytes: 256
n,q = map(int, input().split())
s = input()

t = [0 for i in range(n+1)]
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2]=="AC" else 0)

for i in range(q):
    l,r = map(int, input().split())
    print(t[r-1]-t[l-1])


Measured memory_bytes: 7772