akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}



template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}



vector<long> dp(1000000, -1);
long n;


int main() {


  cin >> n;

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

  long ans = 0;

  vector<vector<long>> dp(n+1,vector<long>(3,0));

  for(int i=1;i<=n;i++){
    for (int j = 0; j < 3; ++j){
      if (j==0){
        dp[i][j] = max(dp[i-1][1]+b[i-1],dp[i-1][2]+c[i-1]  );
      }
      if (j ==1){
        dp[i][j] = max(dp[i-1][0]+a[i-1],dp[i-1][2]+c[i-1]  );
      }
      if (j==2){
        dp[i][j] = max(dp[i-1][0]+a[i-1],dp[i-1][1]+b[i-1]);
      }
    }
  }



  ans = *max_element(dp[n].begin(),dp[n].end());



  cout << ans;
}























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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define fi first
#define se second
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  int N;
  cin >> N;
  vector<int> x(N + 2), y(N + 2), r(N + 2);
  x[0] = xs, y[0] = ys, r[0] = 0;
  rep(i, 1, N + 1) { cin >> x[i] >> y[i] >> r[i]; }
  x[N + 1] = xt, y[N + 1] = yt, r[N + 1] = 0;
  dump(x);
  dump(y);
  dump(r);

  auto d = [&](int a, int b) {
    double aa = abs(x[a] - x[b]);
    double bb = abs(y[a] - y[b]);
    double dd = sqrt(aa * aa + bb * bb);
    return max(0.0, dd - r[a] - r[b]);
  };
  vector<int> color(N + 2, 0);
  vector<double> dist(N + 2, 1e30);
  using pdi = pair<double, int>;
  priority_queue<pdi, vector<pdi>, greater<pdi>> pq;
  dist[0] = 0;
  pq.push(pdi(0, 0));
  while (pq.size()) {
    pdi a = pq.top();
    pq.pop();
    if (a.fi > dist[a.se])
      continue;

    color[a.se] = 1;
    rep(i, 0, N + 2) {
      if (i == a.se or color[i])
        continue;
      if (chmin(dist[i], dist[a.se] + d(a.se, i))) {
        pq.push(pdi(dist[i], i));
      }
    }
  }
  cout << dist[N + 1] << endl;

  return 0;
}


Measured memory_bytes: 6004
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const int MAX = 10005;

class edge {
  public:
  int t, c;

  edge() {}
  edge(int t, int c): t(t), c(c) {}

  bool operator < (const edge &e) const {
    return c > e.c;
  }
};

vector<edge> to[MAX];
bool seen[MAX];
int n, sum;

void dijkstra() {
  rep(i, n) seen[i] = false;
  sum = 0;

  edge te;
  priority_queue<edge> pq;
  pq.push(edge(0, 0));
  while (!pq.empty()) {
    te = pq.top();
    pq.pop();
    if (seen[te.t]) continue;

    seen[te.t] = true;
    sum += te.c;
    
    for (edge e: to[te.t]) {
      if (seen[e.t]) continue;
      pq.push(e);
    }
  }
}

int main() {
  int m, s, t, w;
  cin >> n >> m;
  rep(i, m) {
    cin >> s >> t >> w;
    to[s].push_back(edge(t, w));
    to[t].push_back(edge(s, w));
  }

  dijkstra();

  cout << sum << endl;


  
  return 0;
}


Measured memory_bytes: 6736
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI_()
    B = LI()
    C = LI()

    ans = 0
    for i in range(N - 1):
        a0, a1 = A[i], A[i+1]
        ans += B[a0]
        if a1 - a0 == 1:
            ans += C[a0]
    ans += B[A[N-1]]

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10080
#include<bits/stdc++.h>
using namespace std;
const int N = 1<<19;
int n,n2;
int a[N], m1[N], m2[N], b[N];
int main(){
	scanf("%d",&n);
	n2 = (1<<n);
	for(int i=0; i<n2; i++){
		scanf("%d",&a[i]);
		m1[i] = i;
		m2[i] = -1;
	}
	for(int t=0; t<n; t++)
		for(int i=0; i<n2; i++)if(i&(1<<t)){
			int i2 = i-(1<<t);
			if(m1[i2] != m1[i] && m1[i2] != m2[i]){
			if(a[m1[i2]] > a[m1[i]]){
				m2[i] = m1[i];
				m1[i] = m1[i2];
			}else
			if(m2[i] == -1 || a[m1[i2]] > a[m2[i]]){
				m2[i] = m1[i2];
			}
			}
			if(m2[i2] != m1[i] && m2[i2] != m2[i]){
				if(m2[i2] != -1 && (m2[i] == -1 || a[m2[i2]] > a[m2[i]])){
					m2[i] = m2[i2];
				}
			}
		}
	b[0] = 0;
	for(int i=1; i<n2; i++){
		b[i] = max(a[m1[i]] + a[m2[i]], b[i-1]);
		printf("%d\n",b[i]);
	}
	return 0;
}


Measured memory_bytes: 10240
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

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

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


int a[5]={0};
int c[14]={0};
int node;
char t;
int tmp;

int main(){
	while(cin>>tmp){
		c[tmp]++;
		rep(i,4){
			cin>>t>>tmp;
			c[tmp]++;
		}
		rep(i,14){
			a[c[i]]++;
		}
		bool str=false;
		rep(i,10){
			if(c[i]==1){
				rep(j,4){
					if(c[i+j+1]!=1){
						str=false;
						break;
					}
					else if(j==3) str=true;
				}
				break;
			}
		}
		//rep(i,13) cout<<c[i+1]<<" ";
		//cout<<endl;
		if(c[1]==1&&c[10]==1&&c[11]==1&&c[12]==1&&c[13]==1) str=true;
		if(a[4]==1) cout<<"four card\n";
		else if(a[3]==1&&a[2]==1) cout<<"full house\n";
		else if(str) cout<<"straight\n";
		else if(a[3]==1) cout<<"three card\n";
		else if(a[2]==2) cout<<"two pair\n";
		else if(a[2]==1) cout<<"one pair\n";
		else cout<<"null\n";
		
		rep(i,14) c[i]=0;
		rep(i,5) a[i]=0;
	}
	return 0;
}

Measured memory_bytes: 1124
n,k = map(int,input().split())
arr = list(map(int,input().split()))
dp = [float("inf")]*len(arr)
dp[0] = 0
cost = 0
for i in range(len(arr)):
    for jump in range(i+1,i+k+1):
        if(jump<len(arr)):
            dp[jump] = min(dp[jump],dp[i]+abs(arr[jump]-arr[i]))
print(dp[-1]) 

Measured memory_bytes: 55136
import java.io.*;
import java.util.*;

class Main {

	// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		long N;
		N = sc.nextLong();
		String[] s = new String[(int)(N)];
		for(int i = 0 ; i < N ; i++){
			s[i] = sc.next();
		}
		long M;
		M = sc.nextLong();
		String[] t = new String[(int)(M)];
		for(int i = 0 ; i < M ; i++){
			t[i] = sc.next();
		}
		solve(N, s, M, t);
	}

	static void solve(long N, String[] s, long M, String[] t){
		int ans = 0;
		for(int i = 0;i < s.length;i++){
			int sum = 0;
			for(int j = 0;j < s.length;j++){
				if(s[i].equals(s[j]))sum++;
			}
			for(int j = 0;j < t.length;j++){
				if(s[i].equals(t[j]))sum--;
			}
			if(ans < sum)ans = sum;
		}
		System.out.println(ans);
	}
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

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<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


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

    string ans = "second";
    REP(i, N){
        int a;
        cin >> a;
        if(a % 2 == 1) ans = "first";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n, m;
    std::cin >> n >> m;
    vec<diag_pair<i32>> a(n), b(m);
    for (auto&& p: a) std::cin >> p.first >> p.second;
    for (auto&& p: b) std::cin >> p.first >> p.second;

    for (usize i=0; i<n; i++) {
        vec<i32> dist(m);
        usize ans = n;
        for (usize j=0; j<m; j++) {
            dist.at(j) = std::abs(a.at(i).first-b.at(j).first)
                + std::abs(a.at(i).second-b.at(j).second);
            if (ans==n || dist.at(j) < dist.at(ans)) ans = j;
        }
        std::cout << ans + 1 << '\n';
    }
}


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

int main(){
  int K;
  cin >> K;
  
  string S;
  cin >> S;
  
  if(S.size() <= K){
    cout << S;
  }
  else{
    string split = S.erase(K);
    cout << split << "...";
  }
}

Measured memory_bytes: 3628
//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int H,W,K;
	char S[12][1003];
	int rui[12][1003]={};
	scan(H>>W>>K);
	rep(i,H){
		scan(S[i]);
	}
	rep(i,H){
		rep(j,W){
			rui[i][j+1]=rui[i][j]+(S[i][j]-'0');
		}
	}
	rep(j,W+1){
		rep(i,H){
			rui[i+1][j]+=rui[i][j];
		}
	}
	int bitall=(1<<(H-1));
	int ans=INF;
	rep(bit,bitall){
		int hkire=0;
		int root[10];
		rep(i,H) root[i]=i;
		rep(i,H-1){
			if(bit&(1<<i)){
				hkire++;
			}
			else{
				root[i+1]=root[i];
			}
		}
		int wkire=0;
		int now1[10]={};
		int lastwk=0;
		int flag=1;
		debug(bit,hkire);
		rep(j,W){
			rep(i,H){
				if(S[i][j]-'0'){
					now1[root[i]]++;
					if(now1[root[i]]>K){
						if(j==lastwk){
							flag=0;
							break;
						}
						wkire++;
						lastwk=j;
						j--;
						rep(i,H) now1[i]=0;
						break;
					}
				}
				debug(j,i,now1[root[i]],wkire);
			}
			if(flag==0) break;
		}
		if(flag) ans=min(ans,hkire+wkire);
		debug(flag,bit,hkire,wkire,ans);

	}
	prin(ans);
	return 0;
}


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

string str;
int v[80001];
int d[80001];
int sum[80001];

int solve() {
    for (int i = 0; i < str.size(); i++) {
        int c = str[i] - '0';
        if (i % 2 == 0) {
            v[i] = c + (i ? v[i-1] : 0);
            d[i] = (i ? d[i-1] : 0);
        } else {
            d[i] = c + (i ? d[i-1] : 0);
            v[i] = (i ? v[i-1] : 0);
        }
    }

    for (int i = 0; i < str.size(); i++) {
        sum[i] = (11 + (((v[i] - d[i]) % 11))) % 11;
    }

    int m[11] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};;
    int ans = 0;
    for (int i = 0; i < str.size(); i++) {
        ans += m[sum[i]];
        if (i + 1 < str.size() && (str[i+1] - '0') != 0) {
            m[sum[i]]++;
        }
    }

    return ans;
}

int main() {
    while (cin >> str, str != "0") cout << solve() << endl;

    return 0;
}

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

int main(){
  constexpr int Nmax= 200'000;
  constexpr int Nbit= Nmax+ 1;
  int N;
  cin >> N;

  vector<int> mod2(N+1);
  for(int d=1; d<= N; d++){
    cin >> mod2.at(d);
  }

  bitset<Nbit> bs;
  for(int d=N; d>=1; d--){
    int cnt_mul= 0;
    for(int m= 2*d; m<= N; m+=d){
      if(bs.test(m)){
        cnt_mul++;
      }
    }
    cnt_mul %= 2;

    if(mod2.at(d)==0){
      if(cnt_mul==1){ bs.set(d); }
    }
    else{
      if(cnt_mul==0){ bs.set(d); }
    }
  }

  cout << bs.count() << endl;
  for(int d=1; d<=N; d++){
    if(bs.test(d)){
      cout << d <<" ";
    }
  }
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    int a;
    bool approved = true;
    for(int i = 0; i < n; i++){
        cin>> a;
        int tmp = a;
        if(a%2 == 0)
            if(a%3!=0 && a%5!=0){
                approved = false;
            }
    }
    if(approved)
        cout<<"APPROVED"<<endl;
    else
        cout<<"DENIED"<<endl;
}


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

namespace ARC080D {
    class Program {
        static void Main(string[] args) {
            int[] HWinput = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int H = HWinput[0];
            int W = HWinput[1];
            int N = int.Parse(Console.ReadLine());
            int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int nownum = 1;
            int dir = 1;
            int nownumcount = 0;
            for (int i = 0; i < H; i++) {
                string str = "";
                for (int j = 0; j < W; j++) {
                    if(dir == 1) {
                        str += nownum.ToString() + " ";
                    } else {
                        str = nownum.ToString() + " " + str;
                    }
                    nownumcount++;
                    if (nownumcount == input[nownum - 1]) {
                        nownum++;
                        nownumcount = 0;
                    }
                }
                Console.WriteLine(str);
                dir = (dir + 1) % 2;
            }
        }
    }
}


Measured memory_bytes: 17520
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
// #define DEBUG_MODE
#ifdef DEBUG_MODE
	#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
	#define debug(...)
#endif


int main () { 
#ifdef DEBUG_MODE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d\n", max(a + b, max(2 * a - 1, 2 * b - 1)));
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    out(n*(n+1)/2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i, n) for(int i = n-1; i >= (int)0; i--)
#define erep(i,container) for (auto i : container)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    string s;
    std::cin >> s;
    
    for(int bit=0;bit<(1<<3);bit++){
        std::vector<int> a(4);
    rep(i,4)a[i]=s[i]-'0';
        rep(i,3){
            if(bit&(1<<i))a[i+1]*=-1;
        }
        if(sum(all(a),0)==7){
            std::cout << a[0];
            if(a[1]>=0)std::cout << '+' ;//<< std::endl;
            std::cout << a[1] ;//<< std::endl;
            if(a[2]>=0)std::cout << '+' ;//<< std::endl;
            std::cout << a[2] ;//<< std::endl;
            if(a[3]>=0)std::cout << '+' ;//<< std::endl;
            std::cout << a[3] ;//<< std::endl;
            std::cout << "=7" << std::endl;
            exit(0);
        }
        
    }
}

Measured memory_bytes: 256
#include <iostream>

int f, N;

int main() {
    std::cin >> N;
    int X = N;
    while( N ) {
        f += N%10;
        N  = N/10;
    }
    // std::cout << "f = " << f << std::endl;
    if (X % f) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<stack>
using namespace std;
const int N = 1e5;


int main()
{
	map<string,int> mp;
    int n;
    cin>>n;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    while(n--)
    {
        string s;
        cin>>s;
        mp[s]++;

    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;




    int ab;
    cin>>ab;
} 

Measured memory_bytes: 3644
from sys import stdin
mod = 10**9+7
n,k = map(int,stdin.readline().split())
arr = list(map(int,stdin.readline().split()))
dp = [[0]*(k+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
    lst = [0]
    for j in range(k+1):
        lst.append((lst[-1]+dp[i-1][j])%mod)
        dp[i][j] = (lst[j+1]-lst[max(0,j-arr[i-1])])%mod
print(dp[-1][-1])

Measured memory_bytes: 219504
def resolve():
    n, m, x = map(int, input().split())
    al = list(map(int, input().split()))
    al = sorted(al)
    ans = [0, 0]
    for i in al:
        if i < x:
            ans[0] += 1
        elif x < i:
            ans[1] += 1
    ans = sorted(ans)
    print(ans[0])
resolve()

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

int main() {
  long int n,a,b;
  cin >> n;
  a=1;
  b=n;
  for(int i=1;i<=sqrt(n);i++){
      if(n%i==0){
        if(a+b>=i+n/i){
          a=i;
          b=n/i;
        }
      }
  }
  
  cout << a+b-2 << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }


int main() {
    int N, D;  cin >> N >> D;
    vector<vector<int>> X(N);
    rep(i, N) {
        rep(j, D) {
            int x;
            cin >> x;
            X[i].push_back(x);
        }
    }

    int cnt = 0;
    rep(i, N) {
        REP(j, i+1, N) {
            
            double sum = 0;
            rep(k, D) {
                sum += pow(X[i][k] - X[j][k], 2);
            }
            sum = sqrt(sum);
            if (sum == (int)sum) ++cnt;
            //print(sum << ' ' << (int)sum);
        }
    }

    print(cnt);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<int> deg(n,0);
    vector<vector<int>> edge(n);
    REP(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        deg[a]++;deg[b]++;
        edge[a].pb(b);
        edge[b].pb(a);
    }
    bool flag = 0;
    REP(i,n){
        if(deg[i] % 2 == 1){
            if(flag){
                cout << "No" << endl;
                return 0;
            }
            flag = 1;
        }
    }
    REP(i,n){
        if(deg[i] >= 6){
            cout << "Yes" << endl;
            return 0;
        }
    }
    int d4 = 0;
    REP(i,n) if(deg[i] >= 4) d4++;
    if(d4 >= 3){
        cout << "Yes" << endl;
        return 0;
    }
    else if(d4 == 2){
        vector<int> d4s;
        REP(i,n) if(deg[i] == 4) d4s.pb(i);
        int v = d4s[0];
        int w = d4s[1];
        int npaths = 0;
        for(int x : edge[v]){
            int cur = x;
            int p = v;
            while(cur != v && cur != w){
                p = edge[cur][0] + edge[cur][1] - p;
                swap(p,cur);
            }
            if(cur == w) npaths++;
        }
        if(npaths == 2){
            cout << "Yes" << endl;
        }else if(npaths == 4){
            cout << "No" << endl;
        }
    }else if(d4 <= 1){
        cout << "No" << endl;
    }
}

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

const int N = 200009;
int n, m, a[N], b[N], fa[N], Size[N], ans, cnt[N];

inline int get(int x) {
	if (fa[x] == x) return x;
	return fa[x] = get(fa[x]);
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i) fa[i] = i, Size[i] = 1;
//	for (int i = 1; i <= m; ++ i) scanf("%d", &a[i]);
//	for (int i = 1; i <= m; ++ i) scanf("%d", &b[i]);
//	for (int i = 1; i <= m; ++ i) {
//		int fx = get(a[i]), fy = get(b[i]);
//		if (fx == fy) continue;
//		fa[fx] = fy;
//		Size[fy] += Size[fx];
//	}
	while(m --) {
		int x, y;
		scanf("%d%d", &x, &y);
		x = get(x), y = get(y);
		if (x != y) fa[y] = x, Size[x] += Size[y];
	}
//	for (int i = 1; i <= n; ++ i) {
//		int father = get(i);
//		++ cnt[father];
//		ans = max(ans, cnt[father]);
//	}
	for (int i = 1; i <= n; ++ i) if (get(i) == i) ans = max(ans, Size[i]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n"
#define deb3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	
int gcd(int a, int b){ if(a==0) return b; return gcd(b%a, a);}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//ci(t);
	while(t--){
		string s;
		ci(s);
		if(s=="RRR") co(3);
		else if(s=="RRS" || s=="SRR") co(2);
		else if(s=="RSS" || s=="SRS" || s=="SSR" || s=="RSR") co(1);
		else co(0);
	}
	return 0;
}



Measured memory_bytes: 3632
// https://atcoder.jp/contests/abc118/tasks/abc118_c

// http://ctylim.hatenablog.com/entry/2015/08/30/191553
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cstdio>

#define ALL(a) (a).begin(), (a).end()
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define MAXINDEX(c) distance((c).begin(), max_element((c).begin(), (c).end()))
#define MININDEX(c) distance((c).begin(), min_element((c).begin(), (c).end()))
#define DEBUG(x) std::cerr << #x << " = " << (x) << " (" << __FILE__ << "::" << __LINE__ << ")" << std::endl;
#define ERROR(s) std::cerr << "Error::" << __FILE__ << "::" << __LINE__ << "::" << __FUNCTION__ << "::" << (s) << std::endl;
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)

#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

template <typename T>
T inputValue(){
  T a;
  std::cin >> a;
  // scanf("%llu", &a);
  return a;
}

void inputArray(int *p, int a){
  rep(i, a){
    std::cin >> p[i];
    // scanf("%d",p+i);
  }
}

template <typename T>
void inputVector(std::vector<T> *p, int a){
  rep(i, a){
    T input;
    std::cin >> input;
    // scanf("%llu", &input);
    p->push_back(input);
  }
}

template <typename T>
void output(T a, int precision){
  if (precision > 0){
    std::cout << std::setprecision(precision) << a << "\n";
  }else{
    std::cout << a << "\n";
  }
}

void print() { std::cout << std::endl; }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail){
  std::cout << head << ",";
  print(std::forward<Tail>(tail)...);
}

using namespace std;


const bool check(vector<int64_t> &h, int64_t A, int64_t B, int64_t n){
  // A*k + B*(n-k) >= h[0]
  // (A-B)*k >= h[0] - B*n
  // k = ( h[0] - B*n + (A-B) -1 ) / (A-B)
  int64_t sum = 0;
  EACH(v, h) {
    int64_t k = ( *v - B*n + (A-B) -1 ) / (A-B);
    // cout <<"***" << k << endl;
    sum += k;
    if(sum>n){
      return false;
    }
  } 
  return true;
}

int main(int argc, char **argv)
{
  int64_t N, A, B;
  scanf("%lld%lld%lld",&N, &A, &B);
  // print(N, A, B);
  vector<int64_t> h(N);
  FOR(i,0,N){
    scanf("%lld", &h[i]);
  }
  RSORT(h);
  // EACH(i,h){
    // print(*i);
  // }
  // print(check(h,A,B,1));
  // print(check(h,A,B,2));
  // print(check(h,A,B,3));
  // print(check(h,A,B,4));


  int64_t s = h[0]/A , t = h[0]/B;
  int64_t c = -1;
  bool b;
  while(s <= t){
    c = (s+t)/2;
    b = check(h,A,B,c);
    // print(s,c,t,b);
    if(b==true){
      t = c-1;
    }else {
      s = c+1;
    }
  }

  c = b ? c : c+1;
  cout << c << endl;


  return 0;
}


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

#define lint long long
#define all(it) it.begin(), it.end()
#define FOR(i, n) for(int i = 0; i < n; i++)
#define FORU(i, a, b, s) for(int i = a; i < b; i += s)
#define FORD(i, a, b, s) for(int i = a; i > b; i -= s)
#define endl "\n"
lint INF = 2e18;
lint MOD = 1e9 + 7;

lint i, j, k, t;

struct HashPair {

    static size_t m_hash_pair_random;

    template <class T1, class T2>
    size_t operator()(const pair<T1, T2> &p) const {

        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);

        size_t seed = 0;
        seed ^= hash1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        seed ^= hash2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        seed ^= m_hash_pair_random + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
    }
};
size_t HashPair::m_hash_pair_random = (size_t)random_device()();

pair<lint, lint> div(lint n) {
    pair<int, int> ret = {0, 0};
    while(true) {
        if(n % 2 == 0) {
            ret.first += 1;
            n /= 2;
        } else if(n % 5 == 0) {
            ret.second += 1;
            n /= 5;
        } else {
            break;
        }
    }
    return ret;
}

int main() {

    lint N;
    cin >> N;

    unordered_map<pair<lint, lint>, lint, HashPair> count25;

    FOR(i, N) {
        string s;
        cin >> s;

        string g;
        if(count(s.begin(), s.end(), '.') != 0) {
            while(s.back() != '.') {
                g.push_back(s.back());
                s.pop_back();
            }
            s.pop_back();
            reverse(g.begin(), g.end());
        }
        while((int)g.length() < 9)
            g.push_back('0');

        lint x = stoi(s) * 1000000000LL + stoi(g);
        count25[div(x)] += 1;
    }

    vector<pair<lint, lint>> keys;
    for(const auto &it : count25) {
        keys.emplace_back(it.first);
    }

    lint ans = 0;
    for(auto &k1 : keys) {
        for(auto &k2 : keys) {
            if(k1.first + k2.first >= 18 && k1.second + k2.second >= 18) {
                if(k1.first == k2.first && k1.second == k2.second) {
                    ans += count25[k1] * (count25[k1] - 1);
                } else {
                    ans += count25[k1] * count25[k2];
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int h, w;
string s[1010];
vector<vector<int>> dist(1010,vector<int>(1010, inf));
int main(){
    cout << fixed << setprecision(10);
    cin >> h >> w;
    rep(i,h) cin >> s[i];
    ll ans = 0;
    vector<pair<int,int>> vii;
    rep(i,h){
        rep(j,w){
            if(s[i][j] == '#'){
                dist[i][j] = 0;
                vii.push_back({i,j});
            }
        }
    }
    queue<pair<int,int>> que;
    for(auto u : vii) que.push({u.first, u.second});
    while(!que.empty()){
        int x = que.front().first, y = que.front().second;
        que.pop();
        int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};
        rep(i,4){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < h && ny >= 0 && ny < w){
                if(dist[nx][ny] == inf){
                    dist[nx][ny] = dist[x][y] + 1;
                    ans = dist[x][y] + 1;
                    que.push({nx,ny});
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i, h) cin >> a[i];

    vector<bool> tate(w, false), yoko(h, false);

    rep(i, w) {
        bool f = true;

        rep(j, h) if (a[j][i] == '#') f = false;

        tate[i] = f;
    }

    rep(i, h) {
        bool f = true;

        rep(j, w) if (a[i][j] == '#') f = false;

        yoko[i] = f;
    }

    vector<string> res;

    rep(i, h) {
        if (yoko[i]) continue;
        string p = "";
        rep(j, w) {
            if (tate[j]) continue;
            p += a[i][j];
        }
        res.push_back(p);
    }
    
    rep(i, res.size()) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, T, E; cin >> N >> T >> E;
    vector<int> x(N);
    for(int i = 0; i < N; i++) cin >> x[i];
    for(int i = 0; i < N; i++)
    {
        int t = x[i];
        while(t <= T + E)
        {
            if(T - E <= t and t <= T + E)
            {
                cout << i + 1 << endl;
                return 0;
            }
            t += x[i];
        }
    }
    cout << -1 << endl;
    return 0;
}




Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m=1000000000;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=-100;i<=100;i++){
    int c=0;
    for(int j=0;j<n;j++){
      c+=(a[j]-i)*(a[j]-i);
    }
    m=min(m,c);
  }
  cout<<m;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean key = false;
		a : while(true) {
			for (int i = 0;; i++) {
				for (int j = 0;; j++) {
					if ((4 * i + 7 * j) == N) {
						key = true;
						break a;
					} else if (N < j) break;
				}
				if(N < i)break a;
			}
		}
		System.out.println(key?"Yes":"No");
	}	
}

Measured memory_bytes: 22608
import java.util.*;
import java.io.*;

class Main{

     /*
     * https://atcoder.jp/contests/dp/tasks/dp_i
     */ 
 
    public static void main(String[] args){
        
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        double[] dp = new double[n + 1];
        dp[0] = 1.0;
        for(int i = 0; i < n; i++){ // read coin probabilities
            double probabilityHead = in.nextDouble();
            for(int j = i + 1; j >= 0; j--){
                /**
                 * the probability taht we have j heads is the probaility that 
                 * we got a head * the probability of getting j-1 heads or the
                 * probability of not getting a head (1 - prob_head), which means
                 * we still have j heads to pick, hence dp[j].
                 */
                dp[j] = (j == 0 ? 0: dp[j - 1] * probabilityHead) + 
                dp[j] * (1 - probabilityHead);
            }

        }
        double ret = 0;
        for(int index = (n / 2) + 1; index <= n; index++) ret += dp[index];
        System.out.println(ret);
    }
}


Measured memory_bytes: 37764
N = int(input())

W = []
fg = True

for lop in range(N):
    W.append(input())
    
w = set(W)
if not(len(w) == N):
    fg = False
else:
    mae = W[0]
    for lop in range(1,N):
        if not(mae[-1:] == W[lop][0]):
            fg = False
        mae = W[lop]
if fg :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
// 虚無
#include <stdio.h>

using size_type = unsigned int;
constexpr size_type N = 2e6;
char Input[N + 1];
char *input = Input;
bool exist = false;
bool answer[] = {false, false};

int main(void){
    fread(Input, sizeof(char), N, stdin);
    unsigned int n = 0;
    while(*input >= '0') n = 10 * n + (*input++) - '0';
    ++input; const unsigned int m = n - 1;
    for(unsigned int i = 0; i < n; ++i, ++input){
        if(*input == '2'){
            exist = true;
            if((m | i) == m) answer[0] = not answer[0];
        }
        else if(*input == '3'){
            if((m | i) == m) answer[1] = not answer[1];
        }
    }
    if(exist) putchar(answer[0] ? '1' : '0');
    else putchar(answer[1] ? '2' : '0');
    putchar('\n');
    return 0;
}

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

typedef long long ll;
typedef long long ld;
typedef vector<int> vi;
typedef pair<ll, ll> pii;

struct Node
{
    int node, len;
    Node() {node = len = 0;}
    Node(int node, int len) {this -> node = node, this -> len = len;}
};
typedef vector<Node> vg;

#define MAX 2000001
#define NON 0
#define MOD 2019

#define FOR(type, i, a, b) for(type i = a; i < b; i++)
#define FORR(type, i, b, a) for(type i = b; i > a; i--)
#define FORE(type, i, a, b) for(type i = a; i <= b; i++)
#define FORRE(type, i, b, a) for(type i = b; i >= a; i--)

#define testBit(n, bit) ((n >> bit) & 1)
#define flipBit(n, bit) (n ^ (1ll << bit))
#define randomize mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s; cin >> s;
    int len = s.length();
    int save[MAX] = {};
    int pow10 = 1;
    int cnt[2019] = {};
    ll answer = 0;
    FORRE(int, i, len - 1, 0){
        save[i] = ((s[i] - '0') * pow10 + save[i + 1]) % MOD;
        cnt[save[i]]++;
        pow10 *= 10, pow10 %= MOD;
    }
    FOR(int, i, 0, 2019){
        answer += cnt[i] * (cnt[i] - 1) / 2;
        if (i == 0) answer += cnt[i];
    }
    cout << answer;
}

Measured memory_bytes: 11568
H, W, K = map(int,input().split())

mod = 1000000007

fibonacci = [1,1,2,3,5,8,13,21]

Amida = [ [0] * W for h in range(H+1)]

for h in range(H+1):
	if W == 1:
		break
	for w in range(W):
		if h == 0:
			if w == 0:
				Amida[h][w] = 1
			else:
				break
		elif w == 0:
			Amida[h][w] = fibonacci[W-2] * Amida[h-1][w+1] + fibonacci[W-1] * Amida[h-1][w]
		elif w == W-1:
			Amida[h][w] = fibonacci[W-2] * Amida[h-1][w-1] + fibonacci[W-1] * Amida[h-1][w]
		else:
			Amida[h][w] += (fibonacci[w-1] * fibonacci[W-w-1] * Amida[h-1][w-1])
			Amida[h][w] += (fibonacci[w] * fibonacci[W-w-1] * Amida[h-1][w])
			Amida[h][w] += fibonacci[w] * fibonacci[W-w-2] * Amida[h-1][w+1]

		Amida[h][w] = Amida[h][w] % mod

if W == 1:
	if K == 1:
		print(1)
	else:
		print(0)
else:
	print(Amida[H][K-1])

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
int main(){
    int n;
    vector<string> ok;
    scanf("%d",&n);
    rep(i,n){
        string str;
        cin >> str;
        ok.push_back(str);
    }
    int m;
    bool f = false;
    scanf("%d",&m);
    rep(i,m){
        bool c = false;
        string str;
        cin >> str;
        rep(j,n){
            if(ok[j] == str){
                (f) ? f = false : f = true;
                c = true;
                (f) ? printf("Opened by ") : printf("Closed by ");
            }
        }
        if(!c)printf("Unknown ");
        cout << str << endl;
    }
    return 0;
}

Measured memory_bytes: 1268
#include "bits/stdc++.h"

using ll = long long;
using namespace std;

const int N = 2e9;

void solveCase() {

   ll a, b, c, k;
   cin >> a >> b >> c >> k;
   if(k % 2 == 0) {
      cout << a - b << endl;
   } else {
      cout << b - a << endl;
   }
}


int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solveCase();
   }
 
   return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (long long)(1e9+7)
int main(){
	string s;
	cin>>s;
	for(int i=1;i<s.length();i++){
		if((s.length()-i)%2==0){
			int hoge=(s.length()-i)/2;	
			if(s.substr(0,hoge-1)==s.substr(hoge,hoge-1)){
				cout<<hoge*2<<endl;
				return 0;
			}

		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    double G,cnt;
    double Gave,cntave,num = 0;
    while(scanf("%lf,%lf",&G,&cnt) != EOF){
        Gave = Gave + G*cnt;
        cntave = cntave + cnt;
        num = num + 1;
    }
    cntave = cntave / num;
    if(cntave -(double)(int)cntave < 0.5){
        cntave = (double)(int)cntave;
    }
    else{
        cntave = (double)(int)(cntave + 0.9);
    }
    printf("%d\n",(int)Gave);
    printf("%d\n",(int)cntave);
    return 0;
}

Measured memory_bytes: 624
import java.util.Scanner;

public class Main {

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

}


Measured memory_bytes: 24020
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int x,y,z,n,m,road[200005],rail[200005],connect[200005];
pair<pair<int,int>,int> total[200005];

int root (int ind) {
	if (road[ind] == ind) return ind; else 
	return road[ind] = root(road[ind]);
}

void onion(int l, int r) {
	if (root(l) != root(r)) road[root(l)] = root(r);
}

int root2(int ind) {
	if (rail[ind] == ind) return ind; else 
	return rail[ind] = root2(rail[ind]);
}

void onion2(int l, int r) {
	if (root2(l) != root2(r)) rail[root2(l)] = root2(r);
}

int main() {
	cin >> x >> y >> z;
	for (int i = 0; i <= x; i++) {
		rail[i] = i;
		road[i] = i;
	}
	for (int i = 0; i < y; i++) {
		cin >> n >> m;
		onion(n,m);
	}
	for (int i = 0; i < z; i++) {
		cin >> n >> m;
		onion2(n,m);
	}
	for (int i = 1; i <= x; i++) {
		total[i] = make_pair(make_pair(root(i),root2(i)),i);
	}
	sort(total+1,total+1+x);
	total[x+1].f.f = total[x+1].f.s = -31415;
	stack<int> st; while (!st.empty()) st.pop();
	int a1 = 0,a2 = 0,b1 = 0,b2 = 0;
	for (int i = 1; i <= x+1; i++) {
		a1 = total[i].f.f, a2 = total[i].f.s;
		if (!(st.empty() || (a1 == b1 && a2 == b2))) {
			int tmp = st.size();
			while (!st.empty()) {
				connect[st.top()] += tmp-1;
				st.pop(); 
			}
		} 
		b1 = a1, b2 = a2;
		st.push(total[i].second);
	}
	for (int i = 1; i <= x; i++) {
		cout << connect[i]+1 << " ";
	}
}

Measured memory_bytes: 8336
n = int(input())
a = list(map(int, input().split()))
 
# required function 
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = array_sum * array_sum 
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    return (array_sum_square - 
            individual_square_sum)
mod = 10**9+7
  
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
  
print(modinv(2)*int(findProductSum(a, n))%mod)

Measured memory_bytes: 31444
A, B, N = [int(x) for x in input().split()]

Q = A // B
R = A % B

if R == 0:
    ans = Q * (B - 1)
elif B <= N:
    ans = R - 1 + Q * (B - 1)
else:
    ans = int(A * N / B) - A * int(N / B)

print(ans)

Measured memory_bytes: 9000