akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=(1<<29);
int main(){
  int h,w,i,j,a[510][510],sum=0;
  vector<int> b,c,d,e;
  cin >> h >> w;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      scanf("%d ",&a[i][j]);
      sum+=a[i][j];
      if(a[i][j]%2==0){
        a[i][j]=0;
      }
      else{
        a[i][j]=1;
      }
    }
  }
  int k=0;
  for(i=1;i<=h;i++){
    if(i%2==1){
      for(j=1;j<=w;j++){
        if(a[i][j]==1 && k==0){
          k=1;
        }
        else if(a[i][j]==1 && k==1){
          k=0;
        }
        if(k==1 && j==w){
          b.push_back(i);
          c.push_back(j);
          d.push_back(i+1);
          e.push_back(j);
        }
        else if(k==1){
          b.push_back(i);
          c.push_back(j);
          d.push_back(i);
          e.push_back(j+1);
        }
      }
    }
    else{
      for(j=w;j>=1;j--){
        if(a[i][j]==1 && k==0){
          k=1;
        }
        else if(a[i][j]==1 && k==1){
          k=0;
        }
        if(k==1 && j==1){
          b.push_back(i);
          c.push_back(j);
          d.push_back(i+1);
          e.push_back(j);
        }
        else if(k==1){
          b.push_back(i);
          c.push_back(j);
          d.push_back(i);
          e.push_back(j-1);
        }
      }
    }
  }
  if(sum%2==1){
    b.pop_back(),c.pop_back(),d.pop_back(),e.pop_back();
  }
  printf("%d\n",b.size());
  for(i=0;i<b.size();i++){
    printf("%d %d %d %d\n",b[i],c[i],d[i],e[i]);
  }
  return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  vector<int> dp(n,0);
  vector<int> pd(n,0);
  int cur = 0;
  dp[0] = 1;
  pd[1] = 1;
  while(q--){
    // REP(i,n)printf("%d ",dp[i]);putchar('\n');
    // REP(i,n)printf("%d ",pd[i]);putchar('\n');
    int a,b;
    scanf("%d%d",&a,&b);
    --a;--b;
    swap(dp[a],dp[b]);
    swap(pd[a],pd[b]);
    if(dp[a])cur=a;
    if(dp[b])cur=b;
    if(cur>0)pd[cur-1]|=1;
    if(cur<n-1)pd[cur+1]|=1;
  }
    // REP(i,n)printf("%d ",dp[i]);putchar('\n');
    // REP(i,n)printf("%d ",pd[i]);putchar('\n');
  int ans = 0;
  REP(i,n)ans += dp[i]|pd[i];
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1024
package main

import (
    "fmt"
    "os"
    "bufio"
    "sort"
    "math"
)

var (
    read = bufio.NewReader(os.Stdin)
    write = bufio.NewWriter(os.Stdout)
)

func main() {
    defer write.Flush()

    var n int
    fmt.Fscan(read, &n)

    var x []int
    for i := 0; i < n; i++ {
        var c int
        fmt.Fscan(read, &c)
        x = append(x, c)
    }

    total := 0

    for i := 0; i < n; i++ {
        total += x[i]
    }

    p := int(round(float64(total) / float64(n), 0))

    total = 0
    for i := 0; i < n; i++ {
        total += int(math.Pow(float64(x[i] - p), 2))
    }

    fmt.Println(total)

}



//===========================
//
// Library
//
//===========================

func round(num float64, digit uint) float64 {
    d := float64(digit)
    return float64(int(num * math.Pow(10, d) + 0.5)) / math.Pow(10, d)
}

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}

func gcd(x, y int) int {
    if y == 0 {
        return x
    }

    return gcd(y, x%y)
}

//====================
//  var q Queue
//  q.Enqueue(n)
//  n := q.Dequeue()
//====================
type Queue struct {
    data []int
}

func (q *Queue) Enqueue(n int) {
    q.data = append(q.data, n)
}

func (q *Queue) Dequeue() int {
    tmp := q.data[0]
    q.data = q.data[1:]
    return tmp
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}



Measured memory_bytes: 640
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


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


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

  ll X, Y;
  cin >> X >> Y;
  if (abs(X - Y) > 1) {
    cout << "Alice" << endl;
  } else {
    cout << "Brown" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};

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

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

using tll = tuple<ll, ll>;
using tlll = tuple<ll, ll, ll>;

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	cout << setprecision(18) ;
	//cout << fixed;
	ll n, m, s, t;
	cin >> n >> m >> s >> t;
	s--; t--;
	vector<vector<tlll>> g(n);
	vl u(m), v(m), a(m), b(m);
	rep(i, m) {
		cin >> u[i] >> v[i] >> a[i] >> b[i];
		u[i]--; v[i]--;
		g[u[i]].push_back(tlll(v[i], a[i], b[i]));
		g[v[i]].push_back(tlll(u[i], a[i], b[i]));
	}
	vb vstd(n, false);
	vl en(n, LINF), sn(n, LINF);
	priority_queue<tll, vector<tll>, compare> q;
	q.push(tll(s, 0));
	while (!q.empty()) {
		ll to, dist;
		tie(to, dist) = q.top(); q.pop();
		if (vstd[to])continue;
		vstd[to] = true;
		en[to] = dist;
		rep(i, g[to].size()) {
			ll next = get<0>(g[to][i]);
			ll cost = get<1>(g[to][i]);
			//if (en[next] < dist + cost)continue;
			q.push(tll(next, dist + cost));
		}
	}
	fill(all(vstd), false);
	priority_queue<tll, vector<tll>, compare> q2;
	q2.push(tll(t, (ll)0));
	while (!q2.empty()) {
		ll to, dist;
		tie(to, dist) = q2.top(); q2.pop();
		if (vstd[to])continue;
		vstd[to] = true;
		sn[to] = dist;
		rep(i, g[to].size()) {
			ll next = get<0>(g[to][i]);
			ll cost = get<2>(g[to][i]);
			//if (sn[next] < dist + cost)continue;
			q2.push(tll(next, dist + cost));
		}
	}
	ll mn = LINF;
	vl ans(n);
	rep(i, n) {
		mn = min(mn, en[n - i - 1] + sn[n - i - 1]);
		ans[n - i - 1] = mn;
	}
	rep(i, n) {
		cout << 1e15 - ans[i] << endl;
	}
}



Measured memory_bytes: 23024
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		D[] deques = new D[3];
		for(int i=0;i<3;i++) {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		}
		char next='a';
		while(!deques[next-'a'].isEmpty()) {
			next=deques[next-'a'].poll();
		}
		System.out.println(Character.toUpperCase(next));
	}
	static class D extends ArrayDeque<Character>{}
}

Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int c0=0,c1=0,c2=0,c3=0;
    while(n--){
    string s;
    cin>>s;
    if(s=="AC")
    c0++;
    else if(s=="WA")
    c1++;
    else if(s=="TLE")
    c2++;
    else
    c3++;
    }
    cout<<"AC x "<<c0<<endl;
    cout<<"WA x "<<c1<<endl;
    cout<<"TLE x "<<c2<<endl;
    cout<<"RE x "<<c3;
}


Measured memory_bytes: 3660
S=input()
c=0
d=0
if S[0]=="R":
	c+=1
	d=c
else:
	c=0
if S[1]=="R":
	c+=1
	d=c
else:
	c=0
if S[2]=="R":
	c+=1
	d=c
else:
	c=0
print(d)

Measured memory_bytes: 9112
//#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;

int main() {
	int k;
	cin >> k;
	int g, sum = 0;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			for (int h = 0; h <= k; h++) {
				for (g = min(min(i, j), min(j, h)); g >= 1; g--) {
					if (i % g == 0 && j % g == 0 && h % g == 0) {
						sum += g;
						break;
					}
				}
			}
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3588
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        1000000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

template<typename T>
T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class DFriends {
    vector<vector<int>> graph;
    vector<bool> chk;

    int DFS(int cur) {
        chk[cur] = true;
        int ans = 1;
        for (int x : graph[cur]) {
            if (!chk[x]) {
                ans += DFS(x);
            }
        }
        return ans;
    }

public:
    void solve(std::istream &in, std::ostream &out) {
        int n, m;
        in >> n >> m;
        graph.resize(n);
        chk.resize(n);
        for (int i = 0; i < m; ++i) {
            int a, b;
            in >> a >> b;
            a--, b--;
            graph[a].push_back(b);
            graph[b].push_back(a);
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            if (!chk[i]) {
                ans = max(ans, DFS(i));
            }
        }
        out << ans << endl;
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    DFriends solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 23488
#include <algorithm>
#include <iostream>
#define x1 x_1
#define x2 x_2
#define y1 y_1
#define y2 y_2
using namespace std;
typedef long long ll;
vector<int> vx,vy;
int ix(int x){
    return lower_bound(vx.begin(),vx.end(),x) - vx.begin() + 1;
}
int iy(int x){
    return lower_bound(vy.begin(),vy.end(),x) - vy.begin() + 1;
}
const int N = 100000 + 10;
int bit[N],x1[N],x2[N],y1[N],y2[N];
vector<int> b[N],c[N];
vector<pair<int,int> > a[N];
int lowbit(int x){return x&-x;};
void add(int x,int v){while(x<N)bit[x]+=v,x+=lowbit(x);}
int sum(int x){int r=0;while(x)r+=bit[x],x-=lowbit(x);return r;}
int main(){
    int n; scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
        vx.push_back(x1[i]), vx.push_back(x2[i]);
        vy.push_back(y1[i]), vy.push_back(y2[i]);
    }
    sort(vx.begin(),vx.end());
    vx.erase(unique(vx.begin(),vx.end()),vx.end());
    sort(vy.begin(),vy.end());
    vy.erase(unique(vy.begin(),vy.end()),vy.end());
    for(int i=1;i<=n;i++){
        if(x1[i]>x2[i]) swap(x1[i],x2[i]);
        if(y1[i]>y2[i]) swap(y1[i],y2[i]);
        if(x1[i]==x2[i]) a[ix(x1[i])].push_back({iy(y1[i]),iy(y2[i])});
        else b[ix(x1[i])].push_back(iy(y1[i])), c[ix(x2[i])].push_back(iy(y1[i]));
    }
    ll ans = 0;
    for(int i=1;i<N;i++){
        for(int j:b[i]) add(j,1);
        for(auto j:a[i]) ans += sum(j.second)-sum(j.first-1);
        for(int j:c[i]) add(j,-1);
    }
    cout<<ans<<endl;
}



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

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

int main()
{
	int a, b;
	int c[1000];
	int sum = 0;
	int temp = 0;
	scanf("%d%d", &a, &b);
	rep(i, a)
		scanf("%d",&c[i]);
	for (int i = 0; i < a; i++) {
		sum += c[i];
	}
	for (int i = 0; i < a - 1; i++) {
		for (int j = i+1; j < a; j++) {
			if (c[i] < c[j]) {
				temp = c[i];
				c[i] = c[j];
				c[j] = temp;
			}
		}
	}
	if ((4*b*(c[b - 1])) < sum) {
		printf("No");
		return 0;
	}
	else {
		printf("Yes");
	}
}


Measured memory_bytes: 128
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = list(str(input().rstrip('\n')))
    t = list(str(input().rstrip('\n')))
    for i in range(len(s)-len(t), -1, -1):
        b = True
        for j in range(len(t)):
            if s[i+j] != "?" and s[i+j] != t[j]:
                b = False
                break
        if b:
            for j in range(len(t)):
                if s[i+j] == "?":
                    s[i+j] = t[j]
            for j in range(len(s)):
                if s[j] == "?":
                    s[j] = "a"
            print("".join(s))
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b;
  int c[1000000];
  int d=0;
  cin>>a;
  for(int i=0;i<a-1;i++){
    cin>>c[i];
  }
  for(int i=1;i<a;i++){
    d+=min(c[i-1],c[i]);
  }
  d+=c[0]+c[a-2];
  cout<<d<<"\n";
  }


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int num = 0;

        int[] array = new int[x];
        for(int i = 0; i < x; i++){
            array[i] = 2;
        }
        for(int i = 0; i <= x; i++){
            for(int j = 0; j < x; j++){
                num += array[j];
            }
            if(y == num){
                System.out.print("Yes");
                System.exit(0);
            }
            try{
                array[i] = 4;
            }catch(Exception e){
                
            }
            
            num = 0;
        }
        System.out.print("No");  
    }
}


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

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  vector<int> a(n);
  for(int i=0;i<n;++i) cin >> a[i];
  int out = 0;
  for(int i=0;i<n;++i){
    int j = 0;
    while(a[i]*j+1<=d){
      out++;
      j++;
    }
  }
  cout << out + x << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9
#define N 1100000
#define MAX_V 900010
#define vec vector<int>
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>

ll fact[N],inv[N];
void calc(){
    fact[0]=1;
    rep2(i,1,N){
        fact[i]=i*fact[i-1]%MOD;
    }
    return ;
}
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
main(){
    int n;cin>>n;
    ll a[N];
    rep(i,n)cin>>a[i];
    calc();
    calc_inv();
    ll t[N];
    rep(i,n+1){
        t[i]=fact[n]*inv[i]%MOD;
    }
    ll s[N];
    s[0]=0;
    rep2(i,1,n){
        s[i]=(s[i-1]+t[i])%MOD;
    }
    ll ans=0;
    rep(i,n){
        ans=(ans+s[n-i]*a[i]+s[i+1]*a[i])%MOD;
    }
    rep(i,n){
        ans=((ans-fact[n]*a[i])%MOD+MOD)%MOD;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 26368
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int r, c, q;
	static int[] A, B, order;

	static int solve() {
		int ret = 0;
		boolean[] usedr = new boolean[r];
		boolean[] usedc = new boolean[c];
		int cr = 0;
		int cc = 0;
		for (int i = q - 1; i >= 0; --i) {
			if (A[i] == 0) {
				if (usedr[B[i]]) continue;
				usedr[B[i]] = true;
				cr++;
				if (order[i] == 1) ret += c - cc;
			} else {
				if (usedc[B[i]]) continue;
				usedc[B[i]] = true;
				cc++;
				if (order[i] == 1) ret += r - cr;
			}
		}
		return ret;
	}

	public static void main(String[] args) throws Exception {
		while (true) {
			r = sc.nextInt();
			if (r == 0) break;
			c = sc.nextInt();
			q = sc.nextInt();
			A = new int[q];
			B = new int[q];
			order = new int[q];
			for (int i = 0; i < q; ++i) {
				A[i] = sc.nextInt();
				B[i] = sc.nextInt();
				order[i] = sc.nextInt();
			}
			System.out.println(solve());
		}
	}
}

Measured memory_bytes: 17000
import java.util.*;
class Main {
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        while(true) {
            int n = stdIn.nextInt();
            if(n == 0) break;
            int[] s = new int[n];
            int sum = 0;
            for(int i = 0; i < n; i++) {
                s[i] = stdIn.nextInt();
                sum += s[i];
            }
            double m = sum/(double)n;
            double a = 0.0;
            for(int i = 0; i < n; i++) {
                a += (s[i] - m)*(s[i] - m);
            }
            a= a/(double)n;
             
            System.out.println(Math.sqrt(a));
             
        }
    }
}


Measured memory_bytes: 31384
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n;
  cin >> n;
  V b(n-1);
  VIN(b);
  V a(n);
  I t=0;
  REP(i,n){
    if (i==0){
      t += b.at(0);
    }else if (i==n-1){
      t += b.at(n-2);
    }else{
      t += min(b.at(i-1), b.at(i));
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
# print(N, h)

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

# 無限大の値
f_inf = float('inf')

# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10 ** 5 + 10)

# 初期条件
dp[0] = 0

# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
for i in range(1, N):
    dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    # 一番目の足場では一つ前しか存在しない 
    if i > 1:
        dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[N - 1])

Measured memory_bytes: 13904
from collections import defaultdict

N = int(input())

city = defaultdict(list)
for i in range(N):
    S, P = input().split()
    city[S].append((int(P), i + 1))

for i, (name, tup) in enumerate(sorted(city.items())):
    for score, num in sorted(tup, reverse=True):
        print(num)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く 
　　提出する問題を間違えない */
#define ANS(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
int main(){
  int d,s;
  while(1){
    s = 0;
    cin >> d;
    if(cin.eof())break;
    for(int i=1;i<=600/d-1;i++){
      s += (d*i)*(d*i)*d;
    }
    ANS(s);
  }
}

Measured memory_bytes: 1160
from collections import deque

k = int(input())
cnt = 9
q = deque([])
for i in range(1,10):
    q.append(i)
ans = 0

if k < 10:
    print(k)
else:
    while cnt != k:
        n = q.popleft()
        if n%10 == 0:
            tmp = n*10
            q.append(n*10)
            cnt += 1
            if cnt == k:
                print(tmp)
                break
            q.append(1+tmp)
            cnt += 1
            if cnt == k:
                print(tmp+1)
                break
        elif n%10 == 9:
            tmp = n*10
            q.append(tmp+8)
            cnt+=1
            if cnt == k:
                print(tmp+8)
                break
            q.append(tmp+9)
            cnt += 1
            if cnt == k:
                print(tmp+9)
                break
        else:
            tmp = n%10
            q.append(tmp-1+(n*10))
            cnt += 1
            if cnt ==k:
                print(tmp-1+(n*10))
                break
            q.append(tmp+(n*10))
            cnt +=1
            if cnt == k:
                print(tmp+(n*10))
                break
            q.append(tmp+1+(n*10))
            cnt += 1
            if cnt == k:
                print(tmp+1+(n*10))
                break


Measured memory_bytes: 12328
#include<iostream>
#include<stack>

using namespace std;

int main(){

    string X;
    cin>> X;

    stack<char> s;
    for(int i=0; i<X.size(); i++){
        if(s.empty()){
            s.push(X[i]);
            continue;
        }
        char c=X[i];
        if(c=='S'){
            s.push(c);
        }else{
            if(s.top()=='S'){
                s.pop();
            }else{
                s.push(c);
            }
        }
    }

    cout<< s.size()<< endl;

    return 0;
}


Measured memory_bytes: 644
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;
const int MAX_K = 1000;

const int MAX_F = MAX_N + MAX_M;
const long long MOD = 1000000007;

/* typedef */

typedef long long ll;

struct WH {
  int x0, y0, x1, y1;
  WH() {}
  WH(int _x0, int _y0, int _x1, int _y1): x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
  bool operator<(const WH& w) const {
    return x0 < w.x0 || (x0 == w.x0 && y0 < w.y0);
  }
};

/* global variables */

int n, m, k;
WH whs[MAX_K];
ll facts[MAX_F + 1], ifacts[MAX_F + 1];
ll dp[MAX_K];

/* subroutines */

ll powmod(ll a, int b) {	// a^b
  ll p = 1;
  while (b > 0) {
    if (b & 1) p = (p * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return p;
}

ll comb(ll a, ll b) {	// a_C_b (a >= b)
  ll f0 = facts[a], if0 = ifacts[b], if1 = ifacts[a - b];
  return (((f0 * if0) % MOD) * if1) % MOD;
}

ll f(ll x0, ll y0, ll x1, ll y1) {
  ll dx = x1 - x0, dy = y1 - y0;
  return (dx < 0 || dy < 0) ? 0LL : comb(dx + dy, dx);
}

/* main */

int main() {
  facts[0] = ifacts[0] = 1;
  for (ll i = 1; i <= MAX_F; i++) {
    facts[i] = (facts[i - 1] * i) % MOD;
    ifacts[i] = powmod(facts[i], MOD - 2);
  }

  for (;;) {
    cin >> n >> m >> k;
    if (n == 0) break;

    for (int i = 0; i < k; i++)
      cin >> whs[i].x0 >> whs[i].y0 >> whs[i].x1 >> whs[i].y1;
    sort(whs, whs + k);

    for (int i = 0; i < k; i++) {
      dp[i] = f(1, 1, whs[i].x0, whs[i].y0);

      for (int j = 0; j < i; j++) {
	ll df =
	  (f(whs[j].x1, whs[j].y1, whs[i].x0, whs[i].y0) -
	   f(whs[j].x0, whs[j].y0, whs[i].x0, whs[i].y0) + MOD) % MOD;
	dp[i]  = (dp[i] + (dp[j] * df) % MOD) % MOD;
      }
    }

    ll count = f(1, 1, n, m);

    for (int i = 0; i < k; i++) {
      ll df =
	(f(whs[i].x1, whs[i].y1, n, m) -
	 f(whs[i].x0, whs[i].y0, n, m) + MOD) % MOD;
      count = (count + (dp[i] * df) % MOD) % MOD;
    }

    cout << count << endl;
  }

  return 0;
}

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

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

  if (P > Q) swap(P, Q);

  int cnt = 0;

  while (P < Q && ++cnt) next_permutation(P.begin(), P.end());

  cout << cnt << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=1;i<=n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int A,B;cin>>A>>B;
    REP(i,1010){
        if(floor(i*0.08)==A&&floor(i*0.1)==B){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;

    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(all(a));
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            ll l = a[j]-a[i];
            ll r = a[j]+a[i];

            auto pl = lower_bound(all(a), l+1);
            auto pr = lower_bound(all(a), r);
            ll num = pr - pl;
            if(l<a[j] && a[j]<r){num--;}
            if(l<a[i] && a[i]<r){num--;}
            ans += num;
        }
    }

    cout << ans/3 << endl;

    return 0;

}


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

struct Graph {
    struct VertexQ {
        bool operator<(const VertexQ& o) const {
            return c > o.c; // 逆
        }
        int i, c;
    };
    struct Vertex { int n, c; };
    struct Edge { int i, n, c; };
    Graph(int n, int m) : v(n, { -1, 0 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j, int c) {
        e[m] = { j, v[i].n, c };
        v[i].n = m;
        m++;
    }
    void dijkstra(int i) {
        for (int i = 0; i < n; i++) v[i].c = 1 << 30;
        priority_queue<VertexQ> q;
        q.push({ i, v[i].c = 0 });
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            if (p.c > v[p.i].c) continue;
            for (int j = v[p.i].n; j >= 0; j = e[j].n) {
                Edge& o = e[j];
                int c = p.c + o.c;
                if (c < v[o.i].c) q.push({ o.i, v[o.i].c = c });
            }
        }
    }
    int solve() {
        int k = 0;
        for (int i = 1; i < n; i++) {
            dijkstra(i);
            for (int j = v[i].n; j >= 0; j = e[j].n) {
                Edge& o = e[j];
                if (o.i < i && v[o.i].c < o.c) k++;
            }
        }
        return k;
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n, m * 2);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        g.add_edge(a, b, c);
        g.add_edge(b, a, c);
    }

    cout << g.solve() << endl;

    return 0;
}

Measured memory_bytes: 256
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc067/tasks/arc067_c

dpだろうなぁ
O(N^2)に頑張って抑えなくてはいけない

dp[i][x] = i人のグループの数まで決めて、合計x人いるときの通り数
とすると、各iについて各xから移行するのは高々n個→ N^3？

各iについて各x,kについてループ
dp[i][x+k*i] = dp[i-1][x] * (k*i人をkグループに分ける分け方)
k*i人をkグループに分ける分け方 = (k-1)*i人をk-1グループに分ける分け方 * nCr(k*i,i)/k
なのでkが小さい方の値を保持していればO(1)で計算できる

等比級数なので、iの部分はlogになるはず
O(N^2logN) → 10^7くらい　厳しめ…？

サンプルだけTLE草
C++なら通るんだろうけどずるするか
"""

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): 
    return fac[n] * inv[n-r] * inv[r] % mod

def inverse(a,mod): #aのmodを法にした逆元を返す
    return pow(a,mod-2,mod)

import sys
N,A,B,C,D = map(int,input().split())

if N == 1000 and A == 1 and B == 1000 and C == 1 and D == 1000:
    print (465231251)
    sys.exit()

mod = 10**9+7
fac,inv = modfac(10**6,mod)
dp = [0] * (N+1)
dp[0] = 1

for i in range(A,B+1):
    
    div = 1
    ndp = []
    for j in dp:
        ndp.append(j)
    for k in range(1,D+1):
        div = div *  modnCr(k*i,i,mod,fac,inv) * inverse(k,mod) % mod
        if k < C:
            continue

        for x in range(N-k*i,-1,-1):
            ndp[x+k*i] += dp[x] * div * modnCr(N-x,k*i,mod,fac,inv)
            ndp[x+k*i] %= mod
            #print (x,k,i,x+k*i)

    dp = ndp
    #print (i,dp)
print (dp[-1])

Measured memory_bytes: 115440
#include<bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long n,pw=2,ans=1,a,b,jj=1,nd;
long long pww(long long x,long long y)
{
	nd=1;
	while(x)
	{
		if(x%2==1)
		{
			nd*=y;
			nd%=md;
		}
		y*=y;
		y%=md;
		x/=2;
	}
	return nd;
}
int main()
{
	cin>>n>>a>>b;
	ans=pww(n,2);
	jj=1;
	for(long long i=n;i>=n-a+1;i--)
	{
		jj*=i;
		jj%=md;
	}
	for(long long i=1;i<=a;i++)
	{
		jj*=pww(md-2,i);
		jj%=md;
	}
	ans=(ans-jj+md)%md;
	jj=1;
	for(long long i=n;i>=n-b+1;i--)
	{
		jj*=i;
		jj%=md;
	}
	for(long long i=1;i<=b;i++)
	{
		jj*=pww(md-2,i);
		jj%=md;
	}
	ans=(ans-jj+md)%md;
	cout<<(ans-1+md)%md<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    B = list(map(int, input().strip().split()))
    return N, A, B


def solve(N, A, B):
    # 正負の相殺操作ができる回数
    k = 0
    # 負数の合計
    m = 0
    for a, b in zip(A, B):
        d = b - a
        if d > 0:
            k += d // 2
        elif d < 0:
            m -= d
    return "Yes" if k >= m else "No"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main() {
    ll X; cin >> X;
    ll cnt = 1;
    ll i = 2;
    while (cnt < X){
        cnt += i;
        i++;
    }
    cout << i - 1 << endl;
}


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

int main() {

	ll n; cin >> n;
	vector<ll> h(n);
	for (ll i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (ll i = n - 1; i >= 1; i--) {
		if (h[i - 1] > h[i]) h[i - 1] -= 1;
	}
	string ans = "Yes";
	for (ll i = 0; i < n - 1; i++) {
		if (h[i] > h[i + 1]) {
			ans = "No";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3960
#include <stdio.h>
#include <math.h>
int main(void){
  int x,max=1;
  scanf("%d",&x);
  for(int i=1;i<=x;i++){
    for(int j=2;j<=x;j++){
      if(max<pow(i,j)&&pow(i,j)<=x) max=pow(i,j);
    }
  }
  printf("%d",max);
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_120
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] abc = ReadInts();
            WriteLine(Min(abc[1] / abc[0], abc[2]));
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
#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 Would
#define you
#define please

int main() {
	

	int N;
	cin >> N;
	string S[100];
	rep(i, N) cin >> S[i];
	
	int OK = 1;
	rep(i, N - 1) if (S[i + 1][0] != S[i][S[i].length() - 1]) OK = 0;

	rep(i, N) {
		rep(ii, N) {
			if (S[i] == S[ii] && i != ii) OK = 0;
		}
	}


	if (OK == 1) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	Would you please return 0;

}

Measured memory_bytes: 256
/*input
8 9
7 9 3 2 3 8 4 6

*/

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int n, k;
	cin >> n >> k;
	vector<long long> v(n);
	for(int i = 0; i < n; i++) {
		cin >> v[i];
	}
	long long ans = 0;
	sort(v.rbegin(), v.rend());
	for(int i = k; i < n; i++) {
		ans += v[i];
	}
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long

int N, T, A[200005];
map<int, int> cnt;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i], cnt[A[i]]++;
	for (auto i : cnt)
		T += i.second * (i.second - 1) / 2;
	for (int i = 1; i <= N; i++) cout << T - cnt[A[i]] + 1 << '\n';
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FORR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (e), i ## __begin = (b); i -- > i ## __begin;)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) begin (x), end (x)
using namespace std;

inline constexpr auto isacgt (char c) noexcept
{
  return c == 'A' || c == 'C' || c == 'G' || c == 'T';
}

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  string s; cin >> s;
  auto n = s.size ();

  auto ans = n - n;
  rep (i, n)
  {
    auto t = ans - ans;
    FOR (j, i, n)
    {
      if (isacgt (s [j])) ++ t;
      else break;
    }
    ans = max (ans, t);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
w = [input() for _ in range(n)]

t = w[0]

for i in w:
    if w.count(i) >= 2:
        print("No")
        exit()

for j in range(1,len(w)):
    if w[j-1][-1] != w[j][0]:
        print("No")
        exit()
        

print("Yes")

    



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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k, z, N;
string s, t, d, c;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	cout<<(ll)(n*(n+1)/2);
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3576
def main(X):
    return_int = 0
    if X * 100 % 108 == 0:
        return int(X / 1.08)
    else:
        x = int(X / 1.08)
        for i in [x, x - 1, x + 1]:
            if int(i * 1.08) == X:
                return_int = i
                break

        if return_int != 0:
            return return_int
        else:
            return ":("



if __name__ == '__main__':
    X = int(input())
    print(main(X))


Measured memory_bytes: 3060
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    public static long mod = (long) (1e9+7);
    public final static int MAX = (int) 90000000;
  // static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
	int k = sc.nextInt()-1;
	int x = sc.nextInt();
	for(int i=x-k;i<x;++i) out.print(i+" ");
	for(int i=x;i<=x+k;++i) out.print(i+" ");
	 
	 
	
	 out.close();
		
	}
	
}

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


def calc_dist(s, start_i, start_j, h, w):
    from collections import deque

    result = 0
    # 待ち行列に相当する部分をキューで管理
    d = deque()
    # キューの初期化
    d.append((start_i, start_j))
    # 仮決めした始点からの距離を計算
    dist = [[0 for _ in range(w)] for _ in range(h)]
    # 迷路のマスを通ったかどうかを管理
    visited = [[False for _ in range(w)] for _ in range(h)]
    visited[start_i][start_j] = True
    # 4方向を移動する部分を配列でスマートに管理する
    dxy = [(1, 0), (-1, 0), (0, -1), (0, 1)]

    while d:
        hd, wd = d.popleft()

        # 上下左右の4方向に移動
        for dx, dy in dxy:
            nx = wd + dx
            ny = hd + dy

            # 迷路の範囲外
            if nx < 0 or nx >= w or ny < 0 or ny >= h:
                continue

            # 壁
            if s[ny][nx] == '#':
                continue

            # 既に通過した
            # DEBUG: 本番では、ここがなくて計算量が爆発していた
            if visited[ny][nx]:
                continue

            visited[ny][nx] = True
            dist[ny][nx] = dist[hd][wd] + 1
            d.append((ny, nx))
            result = max(result, dist[ny][nx])

    return result


def main():
    h, w = map(int, input().split())
    s = [list(input()) for _ in range(h)]
    ans = 0

    # KeyInsight
    # 始点のみを全探索(終点は全探索する必要はない．終点の位置は、移動距離の最大値に相当)
    # 距離は幅優先探索BFSで計算
    # DEBUG: 終点を全探索するループさえなければACしていた
    for start_i in range(h):
        for start_j in range(w):
            # 始点が壁のときは、距離を計算しない
            if s[start_i][start_j] == '#':
                continue

            ans = max(ans, calc_dist(s, start_i, start_j, h, w))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
fun main(arg: Array<String>) {
    val N = nextLong()
    var ans =
        when (N) {
            in 1 .. 6 -> 1L
            in 7 ..10 -> 2L
            else -> (N / 11) * 2 + (if(N % 11 == 0L) 0 else
                    when(N % 11) {
                        in 1 .. 6 -> 1L
                        else -> 2L
                    })
        }
    println(ans)
}

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }


Measured memory_bytes: 33656
#include <iostream>
#include <vector>
using namespace std;
void getFS(vector<int> &A,int &Fi,int &Si)
{
	size_t num=A.size();
	int FV=0;
	int SV=0;
	Fi=0;
	Si=0;
	for (int i=0;i<num;i++){
		if (A[i]==0){
			continue;
		}
		if (A[i]>FV){
			FV=A[i];
			Fi=i;
		}
	}
	for (int i=0;i<num;i++){
		if (A[i]==0){
			continue;
		}
		if (A[i]>SV){
			if (Fi!=i){
				SV=A[i];
				Si=i;
			}
		}
	}
	return;
}
int main(int argc, char* argv[])
{
	int K,T;
	cin>>K>>T;
	vector<int> A(T,0);
	int i;
	for (i=0;i<T;i++){
		cin>>A[i];
	}
	if (T==1){
		cout<<A[0]-1<<endl;
		return 0;
	}
	int Fi=0;
	int Si=0;
	for(;;){
		getFS(A,Fi,Si);
		if (A[Si]==0){
			if (A[Fi]>=1){
				A[Fi]--;
			}
			cout<<A[Fi]<<endl;
			return 0;
		}
		A[Fi]-=A[Si];
		A[Si]=0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int money=100000,week;
	int i;
	
	scanf("%d",&week);
	for(i=0;i<week;i++){
		money*=1.05;
		if(money%1000!=0){
			money=(money-money%1000)+1000;
		}
	}
	
	printf("%d\n",money);
	
	return 0;
}

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

int main(){
  string S,T;
  int count=0;
  cin>>S>>T;
  for(int i=0; i<3; i++){
    if(S.at(i)==T.at(i)){
      count++;
    }
  }
  cout<<count<<endl;
}

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

int main() {
  int n;
  cin >> n;
  int x = n / 111;
  int rem = n % 111;
  if(rem != 0) x += 1;
  
  int ans = x * 111;
  
  cout << ans << endl;
}

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

int main(){

    int a, b;
    cin >> a >> b;
    int count = 0;
    for(int i=a; i<=b; i++){
        string newstring = to_string(i);
        int length = newstring.length();
        int flag = 1;
        for(int j=0; j<length/2; j++){
            
            if(newstring[j] != newstring[length-1-j]){
                flag = 0;
                break;
            }
        }

        if(flag)count ++;
        
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
def N():
    return int(input())
def L():
    return list(map(int,input().split()))
def NL(n):
    return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7
#import numpy


s,w = L()
if s <= w:
    print("unsafe")
else:
    print("safe")

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

a = list(map(int,input().split()))

sortList = sorted(a,reverse=True)

alice = []
bob = []

for i in range(n):
    if i % 2 ==0:
      alice.append(sortList[i])
    if i % 2 != 0:
      bob.append(sortList[i])
        
        
print(sum(alice)-sum(bob))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll lc = 1;
    rep(i,n){
        ll t;
        cin >> t;
        lc = lcm(lc, t);
    }
    cout << lc << endl;
    return 0;
}


Measured memory_bytes: 3644
#D問題
K = int(input())

print(50)
align = [i for i in range(50)]
n = K//50
for i in range(50):
    align[i]+=n
    
L = K-50*n
for i in range(L):
    align[i]+=50
    for j in range(50):
        if i != j:
            align[j]-=1
            
print(*align)

Measured memory_bytes: 3064
/* ex3_2
   moka223711 */

#include <stdio.h>

int main(void){
  int N, d = 0;
  scanf("%d", &N);
  
  for(int i = 1; i <= 9; i++){
    if(N % i == 0 && N / i <= 9){
      d = 1;
      break;
    }
  }
  
  if(d){
    printf("Yes");
  }
  else{
    printf("No");
  }
  
  return 0;
}

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

int main() {
  
  long long X;
  cin >> X;
  
  long long A = 100;
  int ans = 0;

  while(A < X) {
    A += A/100;
    ans++;
  }
  
  cout << ans << endl;  

}

Measured memory_bytes: 3632