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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
VL dx={1,0,-1,0};
VL dy={0,1,0,-1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll x;
    cin>>x;
    cout<<1-x<<"\n";
    return;
}
int main()
{
    IOS;
    ll t=1,pp;
    //cin>>t;
    pp=t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<": ";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3564
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
  int a,b,c,sum;
  int count=0;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> sum;

  for(int i=0; i<=a; ++i){
    for(int j=0; j<=b; ++j){
      for(int k=0; k<=c; ++k){
        if(i*500 + j*100 + k*50 ==sum) count++;
      }
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
  int n, min=30, i, a, c;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    c=0;
    scanf("%d",&a);
    while(a%2==0){c++;  a/=2;}
    if(c<min) min=c;
  } 
  printf("%d\n",min);

  return 0;
}


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

#define mod 1000000007
int dp[1001][1001];

int main(){
	int h,w;
	cin>>h>>w;
	string s;
	for(int i=0;i<=h;i++)
		dp[i][0]=0;
	for(int i=1;i<=w;i++)
		dp[0][i]=0;
	for(int i=1;i<=h;i++){
		cin>>s;
		for(int j=1;j<=w;j++){
			if(i==1&&j==1)
				dp[i][j]=1;
			else if(s[j-1]=='#')
				dp[i][j]=0;
			else{
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
			}
		}
	}
	cout<<dp[h][w];
}


Measured memory_bytes: 7516
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] main) {
		Scanner sc = new Scanner(System.in);
		int numOfWord = Integer.parseInt(sc.nextLine());
		
		Set<String> wordSet = new HashSet<>();
		boolean followTheRules = true;
		String prevEndChar = null;
		for (int i= 0; i < numOfWord; i++) {
			String word = sc.nextLine();
			
			if (wordSet.contains(word)) {
				followTheRules = false;
				break;
			}
			if (prevEndChar != null && !prevEndChar.equals(String.valueOf(word.charAt(0)))) {
				followTheRules = false;
				break;
			}
			prevEndChar = String.valueOf(word.charAt(word.length() -1));
			wordSet.add(word);
		}
		
		String result = followTheRules ? "Yes" : "No";
		System.out.println(result);
	}
}

Measured memory_bytes: 23124
n,k=map(int,input().split())
a,b,c=map(int,input().split())
t=input()
d={"r":c,"s":a,"p":b}
ans=0
for i in range(n):
    if i<k:
        ans+=d[t[i]]
    elif t[i]!=t[i-k]:
        ans+=d[t[i]]
    else:
        t=t[:i]+"z"+t[i+1:]
print(ans)  

Measured memory_bytes: 3492
n = int(input())

def test():
    ans = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            a, b = str(i), str(j)
            if a[0] == b[-1] and a[-1] == b[0]:
                ans += 1
    print(ans)

c = [[0 for _ in range(9)] for _ in range(9)]
for  i in range(1, n+1):
    first_digit = str(i)[0]
    last_digit = str(i)[-1]
    if first_digit == '0' or last_digit == '0':
        continue
    c[int(first_digit)-1][int(last_digit)-1] += 1
ans = 0
for i in range(1,10):
    for j in range(1, 10):
        ans += c[i-1][j-1]* c[j-1][i-1]
print(ans)

Measured memory_bytes: 40556
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

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

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn a() {
    let s = read!(String);
    let t = read!(String);

    let c_s: Vec<char> = s.chars().collect::<Vec<char>>();
    let t_s: Vec<char> = t.chars().collect::<Vec<char>>();
    let mut ans = 0;
    for i in 0..c_s.len() {
        if c_s[i] == t_s[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn b() {
    let (a, b) = read!(usize, usize);
    if b == 1 {
        println!("0");
        return;
    }
    let mut ans = 1;
    let mut cnt = a;
    while cnt < b {
        ans += 1;
        cnt += a - 1;
    }
    println!("{}", ans);
}

fn c() {
    let n = read!(usize);
    let h = read![[usize]];

    // hを逆転させて最長部分増加列の長さを求める その長さ-1が答え
}

fn d() {
    unimplemented!();
}

fn e() {
    unimplemented!();
}

fn f() {
    unimplemented!();
}

fn main() {
    b();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=1e5+50,P=1e9+7,K=22;

int n,ans;
vector<int> g[N]; 

struct Number { 
	int a[K]; 
	Number(){ mem(a,0); }
} lab[N];

Number operator+(const Number &x,const Number &y){
	Number c; 
	lop(i,0,K)c.a[i]=x.a[i]+y.a[i]; 
	return c;
}

void dfs(int v,int p){
	Number &t=lab[v];
	for(int d:g[v])if(d!=p){
		dfs(d,v); 
		t=t+lab[d];
	}
	p=0; 
	lop(i,0,K)if(t.a[i]>1)p=i+1;
	lop(i,p,K)if(t.a[i]==0){
		t.a[i]=1;
		lop(j,0,i)t.a[j]=0; 
		cmax(ans,i); 
		break;
	}
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	read(n); 
	rep(i,1,n-1){
		int u,v;
		read(u),read(v); 
		g[u].pb(v); 
		g[v].pb(u); 
	}
	dfs(1,0); 
	printf("%d\n",ans);
	return 0; 
}


Measured memory_bytes: 26880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
#define sort(v) sort(v.begin(), v.end())
#define sortr(v) sort(v.rbegin(), v.rend())
void chmin(int &a, int b) {if(a > b) a = b;}
void chmax(int &a, int b) {if(a < b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(s == u){
        cout << a-1 << " " << b;
    }else{
        cout << a << " " << b-1;
    }
}

Measured memory_bytes: 256
/**
 *   author: bholuakku
**/

#include <bits/stdc++.h>
#define For(i,a,b) for(i=(a); i<(b); i++)
#define rep(i,n) for(i=0; i<(n); i++)
#define Nfor(i,a,b) for(i=(a)-1; i>=(b); i--)
#define dep(i,n) for(i=(n-1);i>=0; i--)
#define mp make_pair
#define pb push_back
#define Auto(a) for(auto &val : a)
#define X first
#define Y second
#define MOD 1000000007
#define MOD1 998244353
#define iterate(A, i) for(auto i = A.begin(); i!=A.end(); i++)
#define mset(A,val,n) memset(A, val, n*sizeof(int))
#define Endl cout<<"\n"
#define Test cout<<"Hello\n"

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<bool> vb;
typedef vector<vector<bool> > vvb;
typedef pair<int, int> pii;
typedef vector<vector<pair<int, int> > > vvp;

int power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y>0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x)%p;} return res;}
int modInverse(ll n) {ll p = MOD;return power(n, p-2, p);}
int min(int a, int b, int c) { return min(a, min(b, c)); }
int max(int a, int b, int c) { return max(a, max(b, c)); }
inline void swap(int &a, int &b) { int t = a; a = b; b = t;}
bool cmp(int a, int b){return a>b;}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, w, i, j;
    cin>>n>>w;
    int wt[n], val[n];
    int valMax = 0;
    rep(i, n) {
        cin>>wt[i]>>val[i];
        valMax+=val[i];
    }
    ll dp[n+1][valMax+1];
    ll INF = ll(1e15);
    rep(i,n+1) rep(j, valMax+1) dp[i][j] = INF;
    rep(i, n+1) dp[i][0] = 0;
    For(i,1,valMax+1) if(i==val[0]) dp[0][i] = wt[0];
    For(i,1,n){
        For(j,1,valMax+1){
            dp[i][j] = dp[i-1][j];
            if(j-val[i]>=0)dp[i][j] = min(dp[i][j], wt[i]+dp[i-1][j-val[i]]);
        }
    }
    int ans = -1;
    rep(i, valMax+1) if(dp[n-1][i]<=w) ans = i;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 79104
/**/
#include<bits/stdc++.h>
using namespace std;
char a[100001];
int ans;
int main(){
	ios::sync_with_stdio(false);
	gets(a);
	if(a[0]!='C'){
		ans++;
	}if(a[1]!='O'){
		ans++;
	}if(a[2]!='D'){
		ans++;
	}if(a[3]!='E'){
		ans++;
	}if(a[4]!='F'){
		ans++;
	}if(a[5]!='E'){
		ans++;
	}if(a[6]!='S'){
		ans++;
	}if(a[7]!='T'){
		ans++;
	}if(a[8]!='I'){
		ans++;
	}if(a[9]!='V'){
		ans++;
	}if(a[10]!='A'){
		ans++;
	}if(a[11]!='L'){
		ans++;
	}if(a[12]!='2'){
		ans++;
	}if(a[13]!='0'){
		ans++;
	}if(a[14]!='1'){
		ans++;
	}if(a[15]!='6'){
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int n,l;cin>>n>>l;
  	vector<string> s(n);for(int i=0;i<n;i++) cin>>s[i];
  	sort(s.begin(),s.end());
  	for(int i=0;i<n;i++){
    	cout<<s[i];
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
long long n,N,i,x,Q,p,l,r,last,j;
long long a[150008],b[150008];
long long q[150008][30][2];
long long ans[150008];
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("zty.out","w",stdout);
	scanf("%lld %lld",&N,&Q);
	a[n=1]=N;
	for(i=1;i<=Q;i++)
	{
		scanf("%lld",&x);
		while(a[n]>=x)n--;
		a[++n]=x;
	}
	memset(q,0,sizeof(q));
	q[1][0][1]=a[1];
	b[n]=1; 
	for(i=n;i>=2;i--)
	{
		p=a[i];last=i-1;
		while(p>=a[1])
		{
			l=1;r=last;
			while(l!=r)
			{
				if(a[(l+r+1)/2]<=p)l=(l+r+1)/2;
				else r=(l+r+1)/2-1;
			}
			//q[i][++q[i][0][0]][0]=l;
			//q[i][q[i][0][0]][1]=p/a[l];
		    //b[q[i][q[i][0][0]][0]]+=q[i][q[i][0][0]][1]*b[i];
		    b[l]+=p/a[l]*b[i];
			p=p%a[l];last=l;
		}
		q[i][0][1]=p;
	}
	for(i=n;i>=1;i--)
	{
		ans[q[i][0][1]]+=b[i];
	}
	for(i=N;i>=1;i--)
	  ans[i]+=ans[i+1];
	for(i=1;i<=N;i++)
	  printf("%lld\n",ans[i]); 
	return 0;
} 
/*
5 5 
1 2 0 4 5 
 
8
9
19
22
27
*/

Measured memory_bytes: 75008
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n; cin >> n;
  map<int, int> mp;
  for (int x = 2; x * x <= n; x++) {
    while (n % x == 0) {
      mp[x]++;
      n /= x;
    }
  }
  if (n > 1) mp[n]++;
  int ans = 1;
  dump(mp);
  for (auto& p: mp) {
    ans *= (p.se + 1);
  }
  cout << mp.size() << ' ' << ans - 1 << endl;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;

int main() {
  double n,k,m;
  //int a[100000];
  cin >> n >> k;
  /*rep(i,n){
    cin >> a[i];
    if(a[i]==1)m = i;
  }*/
  cout << ceil((n-1)/(k-1)) << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll tmp[100001];

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


	int N, M, V, P;
	cin >> N >> M >> V >> P;

	int A[100001];
	rep(i, N) cin >> A[i];
	sort(A, A + N);
	reverse(A, A + N);
	tmp[P - 1] = 0;
	for (int i = P - 1; i < N; i++) {
		tmp[i + 1] = tmp[i] + A[i];
	}

	int L = P - 1, R = N;
	while (L + 1 < R) {
		int m = (L + R) / 2;
		int a = A[m] + M;
		if (P > V) {
			if (a >= A[P - 1]) L = m;
			else R = m;
		}
		else if (a < A[P - 1]) R = m;
		else {
			ll kari = ll(N - m - 1 - V + P) * M;
			kari -= tmp[m];
			kari += ll(m - P + 1) * a;

			if (0 <= kari) L = m;
			else R = m;
		}
	}

	co(R);


	Would you please return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int cnt = 0;
    while (n--) {
        int a;
        cin >> a;
        cnt += a % 2;
    }
    cout << (cnt % 2 ? "NO\n" : "YES\n") << '\n';
}


Measured memory_bytes: 384
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
r, s, p = LI()
d = {'r': p, 's': r, 'p': s}
t = S()
ans = 0

# 結果が干渉し合うのは k = 4 とすると
# 1, 5, 9, ...
# 2, 6, 10, ...
# 3, 7, ...
# 4, 8, ...
# となり、各グループごとに独立に考えていい
# それぞれのグループで「連続して同じ手がだせない」じゃんけんをする
# 貪欲法 での解法
for j in range(k):
    is_win_last = False  # 前回勝ったかかどうか
    i = j
    while i < n:
        # 前回と手が同じで、前回は勝っている場合
        if i >= k and t[i - k] == t[i] and is_win_last:
            is_win_last = False
        else:  # 前回と手が異なる場合 もしくは 前回と手が同じだが負けている場合
            ans += d[t[i]]
            is_win_last = True
        i += k


print(ans)


Measured memory_bytes: 9612
#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;
    vector<int> A(N);
    rep(i, N)cin >> A[i];

    int ans = 0, cur = 1;
    rep(i, N) {
        if (A[i] == cur) cur++;
        else ans++;
    }

    if (ans == N)
        cout << -1 << endl;
    else
        cout << ans << endl;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,a,b;
    t = 1;
    while(t--) {
     cin >> a >> b;
     cout << max(a + b, max(a - b, a * b)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, T; cin >> N >> T;
    long long A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<long long> mini(N+1);
    mini[0] = 1e9+7;
    for(int i = 0; i < N; i++) mini[i+1] = min(mini[i], A[i]);

    vector<long long> p(N);
    for (int i = 0; i < N; i++) p[i] = A[i] - mini[i+1];
    int mp = 0, cnt = 1;
    for (int i = 0; i < N; i++)
    {
        if(mp < p[i]) {
            mp = p[i];
            cnt = 1;
        }
        else if(mp == p[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define REP(i,a) for (int i = 0;i < (a);++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(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int duplicate = 0;
    int n;
    cin >> n;
    int a[n];
    map <int,int> mp;
    REP(i,n){
        cin >> a[i];
        mp[a[i]]++;
        if(mp[a[i]]>=2)duplicate++;
    }
    /*cout << duplicate << endl;
    sort(a,a+n);
    REP(i,n)cout << a[i] << " ";
    cout << endl;*/

    int answer = n-duplicate-(duplicate%2);
    cout << answer << endl;


    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

int dp[110][404][110];
int main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  rep(i, 0, N) cin >> w[i] >> v[i];
  int s = w[0] - 1;
  rep(i, 0, N) w[i] -= s;
  rep(i, 0, N) rep(j, 0, 400) rep(k, 0, N + 1) {
    chmax(dp[i + 1][j][k], dp[i][j][k]);
    chmax(dp[i + 1][j + w[i]][k + 1], dp[i][j][k] + v[i]);
  }
  ll ans = 0;
  rep(i, 0, 400) rep(j, 0, N + 1) {
    if(i + (ll)j * s > W) continue;
    chmax(ans, (ll)dp[N][i][j]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 18560
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll k, n;
  cin >> k >> n;
  ll a[200010];
  rep(i, n) cin >> a[i];
  a[n] = a[0] + k;
  ll sum = 0;
  rep(i, n)
  {
    sum += a[i + 1] - a[i];
  }
  ll Min = LINF;
  rep(i, n)
  {
    Min = min(Min, sum - (a[i + 1] - a[i]));
  }
  cout << Min << endl;
  return 0;
}


Measured memory_bytes: 1792
from collections import Counter

N, P = map(int, input().split())
S = input()

if P == 2:
    ret = 0
    for i in range(N):
        if int(S[i]) % 2 == 0:
           ret += i + 1
    print(ret)
    exit()

if P == 5:
    ret = 0
    for i in range(N):
        if int(S[i]) % 5 == 0:
           ret += i + 1
    print(ret)
    exit()

mods = [0] * (N+1)

for i in reversed(range(N)):
    mods[i] = (mods[i+1] + pow(10, N-i-1, P) * int(S[i]))% P

cnt = Counter(mods)
ans = 0
for i in cnt:
    ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)

Measured memory_bytes: 12044
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
    long long n, m;
    cin >> n >> m;
    if (n == 1) {
        if (m > 1) cout << (m-2) << endl;
        else cout << 1 << endl;
    } else if (m == 1) {
        if (n > 1) cout << (n-2) << endl;
        else cout << 1 << endl;
    } else {
        cout << (n-2)*(m-2) << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		new Main().run();
	}
	
	Scanner scanner = new Scanner(System.in);
	int m;
	int[][][] tile = new int[26][2][2];
	boolean[][] cantGet =new boolean[26][2];
	int score = 0;
	
	void run() {
		
		m = scanner.nextInt();
		scanner.nextInt();
		
		for (int color = 0; color < 26; color ++) {
			
			tile[color][0][0] = -1;
			cantGet[color][0] = false;
			cantGet[color][1] = false;
		}
		
		for (int y = 0; y < m; y ++) {
			
			char[] line = scanner.next().toCharArray();
			
			for (int x = 0; x < line.length; x ++) {
				
				if(line[x] != '.') {
					
					int color = line[x] - 'A';
					int index = (tile[color][0][0] == -1) ? 0: 1;
					tile[color][index][0] = x;
					tile[color][index][1] = y;
				}
			}
		}
		
		for (int color = 0; color < 26; color ++) {
			
			if (tile[color][0][0] != -1) {
				
				tryGet(color);
			}
		}
		
		System.out.println(score * 2);
	}
	
	boolean tryGet(int color) {
		
		if (! cantGet[color][0]) {
			
			if ((tile[color][0][0] == tile[color][1][0]
					&& Math.abs(tile[color][0][1] - tile[color][1][1]) == 1)
					|| (tile[color][0][1] == tile[color][1][1]
					&& Math.abs(tile[color][0][0] - tile[color][1][0]) == 1)) {
				
				cantGet[color][0] = true;
				cantGet[color][1] = true;
				return false;
			}
			
			cantGet[color][0] = true;
			if((isEmpty(color, 1, tile[color][0][0], tile[color][0][1], tile[color][1][1])
					&& isEmpty(color, 0, tile[color][1][1], tile[color][0][0], tile[color][1][0]))) {
				
				
				if (tile[color][0][0] != -1) {
					
					tile[color][0][0] = -1;
					score ++;
				}
				return true;
			}
		}
		
		if (! cantGet[color][1]) {
			
			cantGet[color][1] = true;
			if ((isEmpty(color, 1, tile[color][1][0], tile[color][0][1], tile[color][1][1])
					&& isEmpty(color, 0, tile[color][0][1], tile[color][0][0], tile[color][1][0]))) {
				
				
				if (tile[color][0][0] != -1) {
					
					tile[color][0][0] = -1;
					score ++;
				}
				return true;
			}
			cantGet[color][0] = false;
			cantGet[color][1] = false;
		}
		
		return false;
	}
	
	boolean isEmpty(int skip,int axis, int point, int start, int end) {
		
		
		if (start == end) {
			
			return true;
		}
		
		if (start > end) {
			
			int swap = start;
			start = end;
			end = swap;
		}
		
		for (int color = 0; color < 26; color ++) {
			
			if (color == skip
					|| tile[color][0][0] == -1) {
				
				continue;
			}
			
			for (int index = 0; index < 2; index ++) {
				
				if (tile[color][index][1 - axis] == point
						&& tile[color][index][axis] >= start
						&& tile[color][index][axis] <= end
						&& !tryGet(color)) {
					
					return false;
				}
			}
		}
		
		return true;
	}
}

Measured memory_bytes: 12000
#include<cstdio>
#include<algorithm>
#define N 100010

using namespace std;

typedef long long LL;
struct dot{int x,y,i;}d[N];
struct edge{int x,y,v;}e[N+N];
int f[N],n,cnt;
LL ans;

bool cmp(dot a,dot b){
	if(a.x==b.x) return a.y<b.y;
	return a.x<b.x;
}

bool cmp2(dot a,dot b){
	if(a.y==b.y) return a.x<b.x;
	return a.y<b.y;
}

bool cmp3(edge a,edge b){return a.v<b.v;}

int find(int x){return x==f[x]?x:f[x]=find(f[x]);}

int main(){
	int i,t,a,b;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d%d",&d[i].x,&d[i].y);
	sort(d+1,d+n+1,cmp);

	t=n;
	for(i=2,n=1;i<=t;i++)
	if(d[i].x!=d[n].x || d[i].y!=d[n].y) d[++n]=d[i];
	
	for(i=2;i<=n;i++){
		e[++cnt].x=i; e[cnt].y=i-1; e[cnt].v=d[i].x-d[i-1].x;
	}
	for(i=1;i<=n;i++) d[i].i=i;
	//for(i=1;i<=cnt;i++) printf("%d %d %d\n",e[i].x,e[i].y,e[i].v);
	
	sort(d+1,d+n+1,cmp2);
	for(i=2;i<=n;i++){
		e[++cnt].x=d[i].i; e[cnt].y=d[i-1].i; e[cnt].v=d[i].y-d[i-1].y;
	}
	
	for(i=1;i<=n;i++) f[i]=i;
	sort(e+1,e+cnt+1,cmp3);
	for(i=1;i<=cnt;i++){
		a=find(e[i].x); b=find(e[i].y);
		if(a==b) continue;
		f[a]=b; ans+=(LL)e[i].v;
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 4096
n , m  = list(map(int,input().split()))
counter = 0
if n <= m // 2:
    counter = n
    m = m - 2* n
    n = 0
else:
    counter = m //2
    n = n - m //2
    m = 0

counter = counter + m //4 

kouho = m //4
print(max(counter,kouho))

Measured memory_bytes: 3060
S['= r'],m[4]['= r'],z,d[4]={0,-2},k,i;f(i){m[k][i]=S[i]+47?0:m[k][i]?:1+f(d[k]-~i);}main(t){for(scanf("%*d%d ",d),d[2]=-*d-2;S[++i-~*d]=~getchar(););for(;--i;z=fmax(z,t))for(t=k=0;k<4;++k)t+=f(i-~*d);printf("%d",z-3);}

Measured memory_bytes: 78464
MOD = 998244353
class mint:
    def __init__(self, i):
        self.i = i
    def __add__(self, m):
        t = self.i + (m.i if isinstance(m, mint) else m)
        if t > MOD:
            t -= MOD
        return mint(t)
    def __radd__(self, m):
        t = self.i + (m.i if isinstance(m, mint) else m)
        if t > MOD:
            t -= MOD
        return mint(t)
    def __mul__(self, m):
        return mint(self.i * m.i % MOD)
    def __sub__(self, m):
        t = self.i - m.i
        if t < 0:
            t += MOD
        return mint(t)
    def __pow__(self, m):
        i = self.i
        res = 1
        while(m > 0):
            if m & 1:
                res = res * i % MOD 
            i = i * i % MOD
            m >>= 1
        return mint(res)
    def __truediv__(self, m):
        return mint(self.i * (m ** (MOD - 2)).i % MOD)
    def __repr__(self):
        return repr(self.i)

fact_range = 200005
facts = [1] * (fact_range + 1)
for i in range(0, fact_range):
    facts[i+1] = facts[i] * (i + 1) % MOD

ifacts = [1] * (fact_range + 1)
ifacts[fact_range] = pow(facts[fact_range], MOD - 2, MOD)
for i in range(fact_range, 0, -1):
    ifacts[i-1] = ifacts[i] * i % MOD

def comb(n, k):
    if k < 0 or n < k:
        return mint(0)
    else:
        return mint(facts[n] * ifacts[n-k] % MOD * ifacts[k] % MOD)

n, m, k = map(int, input().split())



l = [mint(m) * (mint(m-1) ** (n-1-i)) * comb(n-1, n-1-i) for i in range(n)]
ans = mint(0)
for i in range(k+1):
    ans = ans + l[i]
print(ans)


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}


int main() {
    ll N, K;
    cin >> N >> K;
    cout << N-K+1 << endl;
}


Measured memory_bytes: 256
H, W = [int(item) for item in input().split()]
grid = [[item for item in input().strip()] for _ in range(H)]

# print(H, W) 
# print(grid)

dp = [[0 for _ in range(W+1)] for _ in range(H+1)]
dp[0][1] = 1

for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            pass
        else:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j])%(10**9+7)

print(dp[H][W])

Measured memory_bytes: 52332
d=int(input())

last=[0]*26
c=list(map(int,input().split()))
s=[list(map(int, input().split())) for _ in range(d)]

ans=[]

for i in range(d):

    #何も選択しなかったときの満足度の下がり方
    down=0
    for j in range(26):
        down+=(c[j]*((j+1)-last[j]))
    #何を選ぶか

    score=-1*(10**9)
    kouho=0
    for j in range(26):
        if score<s[i][j]-down+c[j]:
            score=s[i][j]-down+c[j]
            kouho=j+1
    ans.append(kouho)

for item in ans:
    print(item)





Measured memory_bytes: 68368
#include <cstdio>
#include <cctype>
#include <cstring>

using namespace std;

bool len, num, low, upp;
	
int main()
{
	char s[1024];
	
	scanf("%s", s);
	
	len = strlen(s) >= 6;
	
	for (int i = 0; s[i]; i++){
		if (isupper(s[i])) upp = true;
		if (islower(s[i])) low = true;
		if (isdigit(s[i])) num = true;
	}
	
	printf("%s\n", upp && low && num && len ? "VALID" : "INVALID");
	
	return (0);
}

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

int main() {
  int N;
  string A, B, C;
  cin >> N >> A >> B >> C;
  int ans = 0;
  rep(i, N) {
    if (A[i] != B[i] && B[i] != C[i] && C[i] != A[i])
      ans = ans + 2;
    else if (A[i] != B[i] || B[i] != C[i] || C[i] != A[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a==b)cout << a+b << endl;
  else if(a<b)cout << b+b-1 << endl;
  else if(a>b)cout << a+a-1 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

            int n = sc.nextInt();

            if (n == 0)
                break;

            int[] nums = new int[n];

            for (int i = 0; i < n; i++) {
                nums[i] = sc.nextInt();
            }

            int min = Integer.MAX_VALUE;
            for (int i = 0; i < n-1; i++) {
                for (int j = i+1; j < n; j++) {
                    if (Math.abs(nums[i] - nums[j]) < min){
                        min = Math.abs(nums[i] - nums[j]);
                    }
                }
            }
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 48732
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
int a[N], b[N];
int p[N]; // permutation
bool q[N] = {}; // colored vertex

vpii g[N]; // graph
bool u[N] = {}; // visited
vpii v; // dfs
void dfs(int a){
	for(auto &e : g[a]){
		int b = e.first;
		if(u[b]) continue;
		u[b] = true;
		v.EB(b, e.second);
		dfs(b);
		v.EB(a, e.second);
	}
}

int ans[N] = {};

int main(){
	int n, m; scanf("%d%d", &n, &m);
	REP(i, n) scanf("%d%d", a+i, b+i);
	iota(p, p+n, 0);
	sort(p, p+n, [](auto x, auto y){ return a[x] < a[y]; });

	{
		int c = 0;
		REP(i, n){
			int j = p[i];
			if(c != b[j]) q[i] = true;
			c = b[j];
			DEBUG("%d: %dth, x=%d, color=%d\n", i, j, a[j], q[i]);
		}
		if(c) q[n] = true;
		DEBUG("%d: color=%d\n", n, q[n]);
	}
	sort(a, a+n);
	
	REP(i, m){
		int l, r; scanf("%d%d", &l, &r);
		int x = lower_bound(a, a+n, l) - a, y = upper_bound(a, a+n, r) - a;
		DEBUG("[%d, %d] => %d..%d\n", l, r, x, y);
		if(x == y) continue;
		g[x].EB(y, i);
		g[y].EB(x, i);
	}

	REP(i, n+1){
		if(u[i]) continue;
		u[i] = true;
		v.clear();
		dfs(i);
		
		DEBUG("%d\n", i);
		for(auto &e : v){
			DEBUG(" ->%d(%d)\n", e.first, e.second);
		}

		int z = -1;
		if(q[i]) z = i;

		for(auto &e : v){
			if(~z) ans[e.second] ^= 1;
			int j = e.first;
			if(q[j]){
				if(~z){
					if(j != z){
						q[j] = q[z] = false;
						z = -1;
					}
				} else {
					z = j;
				}
			}
		}
		
		if(~z) {
			printf("-1\n");
			return 0;
		}
	}

	int sm = 0;
	REP(i, m) sm += ans[i];
	printf("%d\n", sm);
	REP(i, m) if(ans[i]) printf("%d ", i+1);
}




Measured memory_bytes: 21104
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const ll MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

int n,m,k;
vector<vector<int>>fr;
vector<vector<int>>bl;
vector<bool>vi;
vector<int>cp;
vector<int>cps;

void dfs(int i,int c){
     cp[i] = c;
     vi[i] = 1;
     for(int j = 0;j<fr[i].size();j++){
        if(!vi[fr[i][j]]){
            dfs(fr[i][j],c);
        }
     }
}

void solve(){
     cin >> n >> m >> k;
     fr.resize(n+1);
     bl.resize(n+1);
     for(int i = 0;i<m;i++){
        int v,u;cin >> v >> u;
        fr[v].push_back(u);
        fr[u].push_back(v);
     }
     for(int i = 0;i<k;i++){
        int v,u;cin >> v >> u;
        bl[v].push_back(u);
        bl[u].push_back(v);
     }
     vi.resize(n+1);
     cp.resize(n+1);
     cps.resize(n+1);

     int cnt = 1;
     for(int i = 1;i<=n;i++){
        if(!vi[i]){
            dfs(i,cnt);
            cnt++;
        }
     }
     for(int i = 1;i<=n;i++) cps[cp[i]]++;
     for(int i = 1;i<=n;i++){
        int ans = cps[cp[i]] - fr[i].size() - 1;
        for(int j = 0;j<bl[i].size();j++)
            if(cp[i]==cp[bl[i][j]]) ans--;
        cout << ans <<' ';
     }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 15524
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <array>
#include <bitset>
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'
using namespace std;

template <typename T> struct Modular {
  /* to abbreviate the word "Modular" */
  using M = Modular; 

  /* Infers type from template. The struct/class T must have 
     "modulus" defined as member.*/
  using Type = typename decay<decltype(T::value)>::type; 

  /* Mod() is now an alias to the "modulus" (eg 1e9+7) */
  constexpr static Type Mod() { return  T::value; }

  /* v is the value of the Mint. [0 <= v < Mod) */
  Type v;
  Modular(long long a = 0) : v((a %= Mod()) < 0 ? a + Mod() : a) {}
  M operator-() const { return M() -= *this; }
  M& operator+=(M r) { if ((v += r.v) >= Mod()) v -= Mod(); return *this; }
  M& operator-=(M r) { if ((v += Mod() - r.v) >= Mod()) v -= Mod(); return *this; }
  M& operator*=(M r) { v = (uint64_t)v * r.v % Mod(); return *this; }
  M& operator/=(M r) { return *this *= mdpow(r, Mod() - 2); }
  M& operator++() { return *this += M(1); };
  M& operator--() { return *this -= M(1); };
  friend M operator+(M l, M r) { return l += r; }
  friend M operator-(M l, M r) { return l -= r; }
  friend M operator*(M l, M r) { return l *= r; }
  friend M operator/(M l, M r) { return l /= r; }
  friend bool operator==(M l, M r) { return l.v == r.v; }
  friend M mdpow(M b, unsigned exp) {
    Modular res(1);
    while(exp) {
      if (exp & 1) {
        res *= b;
        if ((res.v += Mod()) >= Mod()) res.v -= Mod();
      }
      b *= b;
      exp >>= 1;
    }
    return res;
  }
};

constexpr unsigned md = 1e9 + 7;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

signed main() {
    fastio;
    int n; 
    cin >> n;
    vector<Mint> a;
    rep (i, n) {
        int ai;
        cin >> ai;
        a.pb(Mint(ai));
    }

    vector<Mint> pre(n+1, Mint(0));
    for (int i = 0; i < n; i++) {
        pre[i + 1] = pre[i] + a[i];
    }

    Mint res(0);
    rep(i, n) {
        Mint sub = pre[n] - pre[i + 1];
        res += sub * a[i];
    }
    cout << res.v << endl;
    
}

Measured memory_bytes: 4564
A1 = list(input().split())
A2 = list(input().split())
A3 = list(input().split())
A = [A1,A2,A3]
N = int(input())
for i in range(N):
  C = input()
  for j in range(3):
    if C == A[0][j]:
      A[0][j] = 'AC'
    if C == A[1][j]:
      A[1][j] = 'AC'
    if C == A[2][j]:
      A[2][j] = 'AC'
for l in range(3):
    if A[l][0] == A[l][1] == A[l][2] == 'AC':
      print('Yes')
      exit()
    if A[0][l] == A[1][l] == A[2][l] == 'AC':
      print('Yes')
      exit()
if A[0][0] == A[1][1] == A[2][2] == 'AC':
  print('Yes')
  exit()
if A[0][2] == A[1][1] == A[2][0] == 'AC':
  print('Yes')
  exit()
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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;
}

double dp[3005][3005] = {0.0};

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

    int n;
    cin >> n;
    vector<double> p(n);
    REP(i, n) { cin >> p.at(i); }

    dp[0][0] = 1.0;
    FOR(i, 1, n + 1) {
        REP(j, i + 1) {
            dp[i][j] += dp[i - 1][j] * (1.0 - p[i - 1]);
            if (j > 0) {
                dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
            }
        }
    }

    /*FOR(i, 0, n + 1) {
        FOR(j, 0, n + 1) { cout << setprecision(4) << dp[i][j] << " "; }
        cout << endl;
    }*/

    double ans = 0.0;
    FOR(i, (n + 1) / 2, n + 1) { ans += dp[n][i]; }
    cout << setprecision(10) << ans << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int i;
  int nn = 1;
  for(i = 0; i < 6; i++){
    if(nn > N) break;
    nn = nn * 10;
  }
  
  //cout << i << endl;
  
  int ans = 0;
  for(int j = 1; j < i; j = j + 2){
  	ans = ans + pow(10, j) - pow(10, j - 1);
    //cout << ans << endl;
  }
  
  if(i % 2 == 1) ans = ans + N - pow(10, i - 1) + 1;
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int solve(int a,int b){
  int c; 
  while(1){
    c = a % b;
    a = b;
    b = c;
    if(c == 0){
      return a;
    }
  }
}
int main() {
  int k;
  cin >> k;
  int ans = 0;
  for(int i = 1;i <= k;i++){
    for(int j = 1; j <= k;j++){
      for(int g = 1; g <= k;g++){
        int mada,dame;
        mada = solve(i,j);
        dame = solve(mada,g);
        ans += dame;
      }
    }
  }
  cout << ans << endl;
}
        
    

Measured memory_bytes: 3636
#include<iostream>

int gcd(int a, int b){
    int remainder;
    while((remainder = (a % b)) != 0) {
        a = b;
        b = remainder;
    }
    return b;
}

int lcm(int a, int b){
    return ((a / gcd(a, b)) * b);
}

int main(){
    int a,b;
    while(std::cin >> a >> b){
        if(a == -1 or b == -1)  break;
        std::cout << gcd(a, b) << " " << lcm(a, b)<< std::endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

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

        int x = scanner.nextInt();
        switch (x%7) {
            case 0:
                System.out.println("thu");
                break;
            case 1:
                System.out.println("fri");
                break;
                case 2:
                System.out.println("sat");
                break;
                case 3:
                System.out.println("sun");
                break;
                case 4:
                System.out.println("mon");
                break;
                case 5:
                System.out.println("tue");
                break;
                case 6:
                System.out.println("wed");
                break;
        }
    }
}



Measured memory_bytes: 26392
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sum(b)/(4*a[1])
out=0
for i in range(a[0]):
  if b[i] >=c:
    out+=1
if out >= a[1]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007

using namespace std;

void solve()
{
    string s;
    cin >> s;
    int N = s.size();
    vector<int> dp(N + 1);
    int mod = 2019;

    map<int, int> hash;

    dp[N] = 0;
    hash[0]++;
    ll ten = 10;
    for (int i = N - 1; i >= 0; i--)
    {
        dp[i] = (dp[i + 1] + (s[i] - '0') * ten) % mod;
        ten *= 10;
        ten %= mod;
        hash[dp[i]]++;
    }

    ll ans = 0;
    for (auto it : hash)
    {
        ll m = it.second;
        ans += m * (m - 1) / 2;
    }
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}


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

namespace Keyence
{
    class B
    {
        static void Main(string[] args)
        {
            string isKeyence = "NO";
            string S = Console.ReadLine();
            for(int i = 0; i < S.Length - 1; i++)
            {
                string str1 = S.Substring(0, i);
                for (int k = i; k < S.Length; k++)
                {
                    string str2 = S.Substring(k);
                    string str = str1 + str2;
                    if(str=="keyence")
                    {
                        isKeyence = "YES";
                        goto label1;
                    }
                }
            }

        label1:
            Console.WriteLine(isKeyence);
        }

    }
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	map<ll, ll> W;
	for (int i=0; i<n; i++) {
		ll a, b; cin >> a >> b;
		if (W.count(b)) W[b] += a;
		else W[b] = a;
	}
	string ret = "Yes";
	ll cnt = 0; 
	for (auto p : W) {
		ll k = p.first;
		ll v = p.second;
		cnt += v;
		if (cnt > k) {
			ret = "No";
			break;
		}
	}
	cout << ret << endl;
	return 0;
}

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

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

    bool yymm, mmyy;

    if(stoi(S.substr(2)) >= 1 && stoi(S.substr(2)) <= 12){
        yymm = true;
    }else{
        yymm = false;
    }

    if(stoi(S.substr(0, 2)) >= 1 && stoi(S.substr(0, 2)) <= 12){
        mmyy = true;
    }else{
        mmyy = false;
    }

    if(yymm && mmyy) cout << "AMBIGUOUS" << endl;
    else if(yymm && !mmyy) cout << "YYMM" << endl;
    else if(!yymm && mmyy) cout << "MMYY" << endl;
    else cout << "NA" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a+b>=c) printf("Yes\n");
	else printf("No\n");
}

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

int main(){
  string s;
  cin >> s;
  for(int i = s.size()-1; i >= 0; i--){
    if(i % 2 == 0){
      int j = i / 2;
      int k;
      for(k = 0; k < i/2; k++, j++){
        if(s[k] != s[j])break;
      }
      if(k == i/2){
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256