akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int N;

int main() {
    cin >> N;
    vector<long long> S(N + 1);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        S[i + 1] = S[i] + a;
    }
    
    int left = 1, right = 3;
    long long ans = 1e15;
    for (int mid = 2; mid < N - 1; mid++) {
        long long half = S[mid];
        
        while (S[left] + S[left + 1] < half) left++;
        long long lmin = min(S[left], half - S[left]), lmax = max(S[left], half - S[left]);
        
        while (S[right] + S[right + 1] < S[N] + S[mid]) right++;
        long long rmin = min(S[right] - S[mid], S[N] - S[right]), rmax = max(S[right] - S[mid], S[N] - S[right]);
        
        ans = min(ans, max(rmax, lmax) - min(rmin, lmin));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = acos(-1.0);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

unsigned GetDigit(unsigned num)
{
    return std::to_string(num).length();
}

int main()
{

    ll n, k, r, s, p, ans = 0;
    string t, te = "";
    cin >> n >> k >> r >> s >> p >> t;
    rep(i, k)
    {
    }
    rep(i, n)
    {
        if (i + 1 < k)
        {
            if (t[i] == 'r')
            {
                ans += p;
                te += 'p';
            }
            else if (t[i] == 's')
            {
                ans += r;
                te += 'r';
            }
            else
            {
                ans += s;
                te += 's';
            }
        }
        else
        {
            if (t[i] == 'r' && te[i - k] != 'p')
            {
                ans += p;
                te += 'p';
            }
            else if (t[i] == 's' && te[i - k] != 'r')
            {
                ans += r;
                te += 'r';
            }
            else if (t[i] == 'p' && te[i - k] != 's')
            {
                ans += s;
                te += 's';
            }
            else
            {
                te += 'n';
            }
        }
    }

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


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
 int n,m,i,j,a[100][100],b;
 scanf("%d %d\n",&n,&m);
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  {
   if (j < m - 1)
                scanf("%d ", &a[i][j]);
            else
                scanf("%d\n", &a[i][j]);
  }
 }
 for(j=0;j<m;j++)
 {
  scanf("%d",&b);
  for(i=0;i<n;i++)
  {
   a[i][j]=a[i][j]*b;
  }
 }
 
    for (i = 0; i < n; i++) {
        b = 0;
        for (j = 0; j < m; j++)
            b += a[i][j];
        printf("%d\n", b);
    }
 return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

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

  int X_day = min(K, N);
  int Y_day = max(0, N-K);

  cout << X*X_day+Y*Y_day << endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
/// functions
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
// end
static long[] f;
// taking inputs
static BufferedReader s;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
// ends
//......................................@uthor_Alx..............................................

public static void main(String[] args) throws  IOException{
       assign();
       long[] nab=long_arr();
       long mod=(long)1e9+7,res=Modpow(2,nab[0],mod);
       res--;
       long res1=1,res2=1;
      for(int i=1;i<=(int)nab[1];i++){
      	res1=(res1*(nab[0]-nab[1]+i))%mod;
      }
       for(int i=1;i<=(int)nab[1];i++){
      	res2=(res2*i)%mod;
      }
      res-=Modmul(res1,ModInv(res2,mod),mod);
      res=(res+mod)%mod;
      res1=1;res2=1;
      for(int i=1;i<=(int)nab[2];i++){
      	res1=(res1*(nab[0]-nab[2]+i))%mod;
      }
       for(int i=1;i<=(int)nab[2];i++){
      	res2=(res2*i)%mod;
      }
      res-=Modmul(res1,ModInv(res2,mod),mod);
      res=(res+mod)%mod;
             out.write(res+"");
        out.flush();
  }
}


Measured memory_bytes: 21460
#include <iostream>

using namespace std;

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

	if (S=="Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (S=="Cloudy") {
		cout << "Rainy" << endl;
	}
	else if (S=="Rainy") {
		cout << "Sunny" << endl;
	}

}





Measured memory_bytes: 3548
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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

#define forn(i, a, n) for (int i = (a); i < (int)n; i++)
#define trav(x, arr) for (auto &x : arr)
#define sz(x) (int)x.size()
#define Matrix(m, h, w) = std::vector<vector<int>> m(h, vector<int> (w)); 
using ll = long long;

#define vi vector<int>
#define vl vector<long>
#define vll vector<ll>

// benq
const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;


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


    vector<string> op = {"AC", "WA", "TLE", "RE"};

    map<string,int> mp {};

    int n; cin >> n;
    while (n--)
    {
      string s; cin >> s;
      mp[s]++;
    }

    for (string s : op){

      int k = mp[s];

      cout << s << " x " << k << "\n";


    }

    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(){
  int w,n,i,tmp1,tmp2,temp;
  int s[33];
  int a,b;
  scanf("%d",&w);
  for(i=0;i<w;i++){
    s[i] = i+1;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d,%d",&a,&b);
    tmp1 = a;
    tmp2 = b;
    temp = s[tmp1-1];
    s[tmp1-1] = s[tmp2-1];
    s[tmp2-1] = temp;
  }
  for(i=0;i<w;i++){
    printf("%d\n",s[i]);
  }
  return 0;
}
    
    
    

Measured memory_bytes: 596
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void Dfs(int node, int parent, int lastColor, VEC(VEC(int))& Edges,
          map<Pii, int>& colorings, int& K)
{
    int start = 1;
    for (int child : Edges[node])
        if (child != parent) {
            if (start == lastColor)
                start++;
            colorings[Pii(node, child)] = start;
            colorings[Pii(child, node)] = start;
            K = max(K, start);
            start++;
            Dfs(child, node, start - 1, Edges, colorings, K);
        }
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(VEC(int)) Edges(N);
    VEC(Pii) EdgeInput;
    FOR(i, 0, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        EdgeInput.push_back(Pii(a, b));
        Edges[a].push_back(b);
        Edges[b].push_back(a);
    }

    map<Pii, int> colorings;
    int K = 0;
    Dfs(0, -1, -1, Edges, colorings, K);
    cout << K << endl;

    for (Pii edge: EdgeInput)
        cout << colorings[edge] << endl;
    return 0;
};

Measured memory_bytes: 21372
#include <iostream>
int main(int argc, char *argv[]) {
  int N, M;
  std::cin >> N >> M;
  int roads[51];
  for (int i = 1; i <= N; ++i)
    roads[i] = 0;
  for (int i = 0; i < M; ++i) {
    int a, b;
    std::cin >> a >> b;
    roads[a]++;
    roads[b]++;
  }
  for (int i = 1; i <= N; ++i)
    std::cout << roads[i] << std::endl;
}


Measured memory_bytes: 256
A,B,K=map(int,input().split())
ans=[]
for i in range(A,A+K):
    if A<=i<=B:
        ans.append(i)
    else:
        break
for t in range(B-K+1,B+1):
    if A<=t<=B: 
        ans.append(t)
    else:
        break
for z in sorted(set(ans)):
    print(z)

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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,k,t,ans;
    cin >> n;
    ans = (n + 999) / 1000;
    ans *= 1000;
    ans -= n;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char s[maxn];
int n;
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	cin>>s;
	n=strlen(s);
	ll ans=0ll;
	ll base=0ll;
	rep(i,0,n)
	{
		if(s[i]=='B')
		{
			base++;
		}else
		{
			ans+=base;
		}
	}
	cout<<ans<<endl;

	
	
    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();} 
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') 
{*p = *p * 10 + ch - '0';}}}

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

namespace abc066_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            if (str.Length % 2 == 1)
            {
                str = str.Remove(str.Length - 1, 1);
            }
            else
            {
                str = str.Remove(str.Length - 2, 2);
            }
            while (str.Substring(0, str.Length / 2) != str.Substring(str.Length / 2, str.Length / 2))
            {
                str = str.Remove(str.Length - 2, 2);
            }
            Console.WriteLine(str.Length);
        }
    }
}


Measured memory_bytes: 13140
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static List<Integer> box;
	
	static int max(int n) {
		int m = 0;
		String s = String.valueOf(n);
		for(int i=0;i<=s.length()-1;i++) {
			for(int j=i+1;j<=s.length()-1;j++) {
				m = Math.max(m, Integer.parseInt(s.substring(i, j))*Integer.parseInt(s.substring(j)));
			}
		}
		return m;
	}
	
	static int count(int n,int cnt) {
		cnt++;
		for(int a:box) {
			if(a==n)
				return -1;
		}
		box.add(n);
		
		if(String.valueOf(n).length()==1) {
			return cnt-1;
		}
		else {
			return count(max(n),cnt);
		}
	}
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		while(q--!=0) {
			int n = sc.nextInt();
			box = new ArrayList<>();
			int cnt=0;
			System.out.println(count(n,cnt));
		}
	}
}


Measured memory_bytes: 36808
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int a=0;
  for(int64_t i=1;i*i<=m;i++)
    if(m%i==0)
      a=max({a,(i<=m/n?(int)i:0),(m/i<=m/n?m/(int)i:0)});
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
const int N=2e5+5;
char s[2][N],f[N];
int main() {
    int h,w,r,c,n;
    scanf("%d%d%d",&h,&w,&n);
    scanf("%d%d%s%s",&r,&c,s[0]+1,s[1]+1);
    bool ok=false;
    int now=c;
    for(int i=1;i<=n;i++) {
        if(s[0][i]=='L') now--;
        if(!now) {
            ok=true;
            break;
        }
        if(s[1][i]=='R') ++now;
        now=std::min(now,w);
    }now=c;
    for(int i=1;i<=n;i++) {
        if(s[0][i]=='R') now++;
        if(now>w) {
            ok=true;
            break;
        }
        if(s[1][i]=='L') --now;
        now=std::max(now,1);
    }now=r;
    for(int i=1;i<=n;i++) {
        if(s[0][i]=='U') now--;
        if(!now) {
            ok=true;
            break;
        }
        if(s[1][i]=='D') ++now;
        now=std::min(now,h);
    }now=r;
    for(int i=1;i<=n;i++) {
        if(s[0][i]=='D') now++;
        if(now>h) {
            ok=true;
            break;
        }
        if(s[1][i]=='U') --now;
        now=std::max(now,1);
    }
    printf("%s",ok?"NO":"YES");
    return 0;
}


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

int main(void) {
	int n, l;
	scanf("%d%d", &n, &l);

	int flavor = l*n + (n-1)*n/2;

	if (l >= 0) printf("%d\n", flavor-l);
	else {
		if (n > -l) printf("%d\n", flavor);
		else printf("%d\n", flavor-l-n+1);
	}
}


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

using namespace std;

int main(){
        int c[3][3];
        for(int i=0;i<3;i++){
                for(int j=0;j<3;j++){
                        cin>>c[i][j];
                }
        }
        string ans="Yes";
        for(int i=0;i<2;i++){
                if(c[0][i+1]-c[0][i]!=c[1][i+1]-c[1][i]||c[0][i+1]-c[0][i]!=c[2][i+1]-c[2][i]||c[i+1][0]-c[i][0]!=c[i+1][1]-c[i][1]||c[i+1][1]-c[i][1]!=c[i+1][2]-c[i][2]){
                        ans="No";
                        break;
                }
        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

int main() {
    int f;
    cin >> f;
    vector<int> v;
    v.push_back(f);
    for(size_t i = 2; i < 1000000; i++)
    {
        if(f % 2 == 0) {
            f = f / 2;
        } else {
            f = 3 * f + 1;
        }
        v.push_back(f);
        for(size_t j = 0; j < v.size()-1; j++)
        {
            if(f == v[j]) {
                cout << i << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{

public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
        int n=s.nextInt();s.nextLine();
        String[] arr=s.nextLine().split(" ");
        for(int i=0;i<n;i++){
        	out.write(arr[0].charAt(i)+""+arr[1].charAt(i));
        }
       
        out.write("\n");
        out.flush();
  }
}


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

int selection(int *,int);

int main()
{
  int *num;
  int kazu,i,count;

  scanf("%d",&kazu);

  num = (int *)malloc(kazu * sizeof(int));

  for(i=0;i<kazu;i++) scanf("%d",&num[i]);

  count = selection(&num[0],kazu);

  for(i=0;i<kazu;i++)
    {
      printf("%d",num[i]);
      if(i != kazu-1) printf(" ");
    }
  printf("\n");

  printf("%d\n",count);

  free(num);
  return 0;
}

int selection(int *num,int kazu)
{
  int i,j,minj,temp,count=0;

  for(i=0;i<kazu-1;i++)
    {
      minj = i;
      for(j=i;j<=kazu-1;j++)
	{
	  if(num[j]<num[minj]) minj =j;
	}

      if(i != minj)
	{
      temp = num[i];
      num[i] = num[minj];
      num[minj] = temp;
      count++;
	}
    }
  return count;
}



Measured memory_bytes: 2048
package main

import "fmt"
var H, W int
var A []string
var dp [][]int
const MOD = int(1e9)+7
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 abs(a int) int {
	if a < 0 { return -a }
	return a
}

func main() {
	_,e := fmt.Scanf("%d%d", &H, &W)
	if e != nil { return }
	A = make([]string, H)
	for i:=0; i<H; i++ {
		_,e = fmt.Scanf("%s", &A[i])
	}
	dp := make([][]int, H)
	for i := range dp {
		dp[i] = make([]int, W)
	}
	dp[0][0] = 1
	for i:=1;i<W;i++ {
		if A[0][i] == '.' {
			dp[0][i] = dp[0][i-1]
		} else { break }
	}
	for i:=1;i<H;i++ {
		if A[i][0] == '.' {
			dp[i][0] = dp[i-1][0]
		} else { break }
	}

	for i:=1; i<H; i++ {
		for j:=1; j<W; j++ {
			if A[i][j] == '.' {
				dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD
			} else {
				dp[i][j] = 0
			}
		}
	}
	fmt.Println(dp[H-1][W-1]%MOD)
}


Measured memory_bytes: 11480
N,K=gets.split.map &:to_i
V=gets.split.map &:to_i
p 0.upto([N,K].min).map{|n|
  0.upto(n).map{|l|
    r = n - l
    d = [0] + V[0...l] + V[(V.size-r)...V.size]
    d.sort!
    (K-n).times{d.shift if d[0]<0}
    d.inject(:+)
  }.max
}.max

Measured memory_bytes: 2044
import java.util.Scanner;

// https://atcoder.jp/contests/abc086/tasks/abc086_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		sc.close();

		int ab = Integer.parseInt(a+b);
		for(int i=0;i<=100100;i++) {
			if(i*i==ab) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");



	}
}


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

class SegmentTree {
private:
    int n;
    vector<ll> node, lazy;
    ll INF = (1ll << 31) - 1;
public:
    SegmentTree(int N) {
        n = 1;
        while (n < N) n *= 2;
        node.resize(2 * n - 1, 0);
        lazy.resize(2 * n - 1, 0);
    }

    void update(int i, int l, int r) {
        if (lazy[i] == 0) return;
        node[i] += lazy[i];
        if (r - l > 1) {
            lazy[2 * i + 1] += lazy[i] / 2;
            lazy[2 * i + 2] += lazy[i] / 2;
        }
        lazy[i] = 0;
    }

    void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        update(k, l, r);
        if (b <= l || r <= a) return;
        
        if (a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            update(k, l, r);
        } else {
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

    ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        update(k, l, r);
        if (b <= l || r <= a) return 0;        
        if (a <= l && r <= b) return node[k];

        ll sum_l = query(a, b, 2 * k + 1, l, (l + r) / 2);
        ll sum_r = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return sum_l + sum_r;
    }

};


int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree st(n);
    for (int i = 0; i < q; i++) {
        int query;
        cin >> query;
        if (query == 0) {
            int s, t;
            ll x;
            cin >> s >> t >> x;
            st.add(s - 1, t, x);
        } else {
            int s, t;
            cin >> s >> t;
            cout << st.query(s - 1, t) << "\n";
        }
    }
    return 0;
}



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

int v[55];
typedef long long ll;
ll A;
int main() {
  int n,K;
  cin >> n >> K;
  for(int i = 0; i < n; i++) cin >> v[i];

  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= n - i; j++) {
      if(i + j > K) continue;
 
      ll ans = 0;
     
      vector<int> tmp;

      for(int k = 0; k < i; k++) {
	ans += v[k];
	tmp.push_back(v[k]);
      }
      
      for(int k = 0; k < j; k++) {
	ans += v[n-1-k];
	tmp.push_back(v[n-1-k]);
      }
      
      sort(tmp.begin(),tmp.end());
      for(int l = 0; l < tmp.size() && l < K - tmp.size() ; l++) {
	if(tmp[l] >= 0) break;
	ans += -tmp[l];
      }
      //  cout << "ans = " << ans <<"i = "<<i<<"  j = "<<j<<endl;
      A = max(ans,A);
    }
  }

  cout << A << endl;
}
    
    
      
      


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int a[100000] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
			cin >> a[i];
	}
	int x = 0;
	
	sort(a, a + n);

	for(int i = 0;i<n;i++){
		if (a[i] == a[i - 1]) {
			continue;
		}
		int k = 0;
		int j = i-1;
		while (((a[j] == a[i]) || (a[j] == a[i] + 1) ||(a[j] == a[i] - 1)) && (j >= 0)) {
			k++;
			j--;
		}
		j = i;
		while( ((a[j] == a[i]) || (a[j] ==a[i] - 1)||(a[j] == a[i]+1)) && (j < n)) {
			k++;
			j++;
		}
		if (x < k) {
			x = k;
		}
	
	
	}
	cout << x << endl;

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<queue>//std::priority_queueを使うために必要です
#include<functional>//デフォルトでpriority_queueは大きい方から出すので、それを逆にするために必要　つまり呪文
#include<vector>//隣接リストの実装や、priority_queueでの呪文に必要

using namespace std;

typedef long long ll;

typedef pair<int, int> P;//priority_queueは距離が小さい順に出力するが、
						 //その際どの頂点なのかがわかるようにstd::pair<int, int>をpriority_queueの保管するデータ型にする

						 //std::pair<int, int>でもいいのだけど、priority_queueのデータ型と紛らわしいので
						 //新しい辺用の構造体を作った。
struct Edge {
	ll to, cost;
	Edge(ll a, ll b) { to = a, cost = b; }
};
//適当な大きな数　本当に適当なのか・・・？
const ll INF = 1145141919810893;
//隣接リストを補完するための二次元ベクター　データ型は先ほど作ったEdge
vector<vector<Edge>> E;
int N;
vector<ll> dis;

void djk(int s) {
	//priority_queueを作る。データ型はstd::pair<int, int>で、
	//<頂点での仮の距離, 頂点>を保存する。
	//降順のpriority_queueはstd::priority_queue<P> pq;で書く
	//今回は昇順なので、下のような呪文が必要
	priority_queue<P, vector<P>, greater<P>> pq;

	//距離を全部INFで埋めておく
	for (int i = 0; i < N; i++)dis[i] = INF;

	//始点の距離は当然0
	pq.push(P(0, s));
	dis[s] = 0;

	//仮の距離候補が存在してる限り、更新などのルーチンを行う。
	while (pq.size()) {
		//このように書くと、priority_queueの一番上、
		//つまりここでは一番小さいものを *読める* (データは取り出したことにはならない)
		P now = pq.top();
		//可読性のために、変数でリネームする
		int pos = now.second, total_dis = now.first;
		//このように書くと、priority_queueの一番上から1つデータを *取り出せる* 
		pq.pop();

		//ここに来るのは、仮の距離候補のうちの最短だが、
		//それがすでに確定してる距離候補より小さいなら無視して次を見る
		if (dis[pos] < total_dis) continue;

		//今の頂点から行けるすべての頂点についてみる
		for (int i = 0; i < E[pos].size(); i++) {
			//可読性のために変数でリネーム
			Edge next = E[pos][i];
			//行先の現時点での距離よりも今の頂点からの方が近いとき、更新する。

			if (dis[next.to] > dis[pos] + next.cost) {
				dis[next.to] = dis[pos] + next.cost;
				//しかし、これも暫定の距離で本当かどうかわからない
				//いったんpriority_queueに挿入して、それが取り出されたときに
				//この頂点で一番近いとき、はじめてそれが確定になる
				pq.push(P(dis[next.to], next.to));
			}
		}
	}
}

int main() {
	
	//N個の頂点
	cin >> N;
	//隣接リストのE[a][b] := 頂点aのb本目(0-idx)の辺　となるので、まずEのサイズをNにする必要がある
	E.resize(N);
	//dis[a] := 始点から頂点aまでの最短距離　今回は始点Sは自由に指定できるようにした
	dis.resize(N);
	for (int i = 0; i < N; i++) {
		int u;
		int k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v;
			ll c;
			cin >> v >> c;
			E[u].push_back(Edge(v, c));
		}

	}
	djk(0);//djk(a) := 0-idxの頂点aを始点として、ほかの点との最短距離を求める
	
	for (int i = 0; i < N; i++) {
		cout << i << " " << dis[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 11876
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){

  char in[101],in_reverse[101];
  int num,cnt=0;

  while(1){
    
    if(scanf("%s",in) == EOF)break;
    
    num=0;
    for(int i=0 ; in[i] != '\0' ; i++){
      num++;
    }
    
    for(int i=0 ; i < num ; i++){
      in_reverse[i]=in[num-1-i];
    }
    in_reverse[num]='\0';
    
    //cout <<in_reverse<<in<<endl;
    
    if(strcmp(in,in_reverse) == 0)cnt++;
    
  }
  
  cout <<cnt<<endl;
  
  
  return 0;
}

Measured memory_bytes: 1156
void main(){
	
	auto NMX = readLine!size_t();
	
	size_t minCost = size_t.max;
	size_t cost;
	
	size_t[][] bookList;
	
	foreach( n ; 0..NMX[0] ){
		bookList ~= readLine!size_t();
	}
	
	size_t[] skillList;
	
	
	foreach( i ; 0..(2.pow(NMX[0])) ){
		skillList = new size_t[](NMX[1]);
		cost = 0;
		
		foreach( size_t j ; 0..NMX[0] ){
			if (  ((i>>j)%2) == 1 ){continue;}
			
			skillList[0..$] += bookList[j][1..$];
			cost += bookList[j][0];
		}
		// skill is enough
		if ( skillList.minElement() >= NMX[2] ){
			if( cost < minCost ){
				minCost = cost;
			}
			//writeln("OK:",skillList,":cost",cost);
		} else {
			//writeln("NG:",skillList,":cost",cost);
		}
	}
	
	if( minCost == size_t.max ){
		writeln(-1);
	} else {
		minCost.writeln();
	}
	
	
	return;
}



import std;


string readStr(){
	return readln().chomp();
}
T[] readLine( T = long )(){
	return readln().split().to!(T[])();
}


Measured memory_bytes: 3900
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	s := nextLine()
	r := 0
	for i := 0; i < len(s); i++ {
		switch s[i] {
		case '-':
			r--
		case '+':
			r++
		}
	}
	fmt.Printf("%d\n", r)
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(4100000)

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

#繰り返し2乗法
def  mod_pow(a:int, b:int, mod:int)->int:
    if b % 2 == 0:
        return (mod_pow(a, b//2, mod) ** 2) % mod
    elif b == 1:
        return a % mod
    else:
        return ((mod_pow(a, b//2, mod) ** 2) * a) % mod

#逆元を求める関数
def mod_inverse(mod:int, b:int)->int:
    return mod_pow(b, mod-2, mod)

#aCbをmodで割った余りを求める関数(bが小さい)
def nCr_mod(n:int, r:int, mod:int)->int:
    num, den = 1, 1 #numerator, denominator

    for i in range(r):
        num = (num * (n-i)) % mod
        den = (den * (i+1)) % mod

    return (num * mod_inverse(mod, den)) % mod

""""
print(mod_pow(2,n, mod))
print(nCr_mod(n, a, mod))
print(nCr_mod(n, b, mod))
"""

ans = (mod_pow(2, n, mod) - 1 - nCr_mod(n, a, mod) - nCr_mod(n, b, mod)) % mod
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
 
using namespace std;
 
 
int main(){
  int h,w,imap[1010][1010],H[1010],W[1010];
  for(int i=0;i<1010;i++)H[i] = W[i] = 0;
  cin >> h >> w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> imap[i][j];
      if(imap[i][j] == 0)H[i]++,W[j]++;
    }
  }
 
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      (H[i]+W[j]-1+imap[i][j])%2==0?cout << 0:cout << 1;
      if(j != w-1)cout << ' ';
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> R;
    if (N < 10) {
        cout << R + 100 * (10 - N) << endl;
    } else
        cout << R << endl;
}

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

using namespace std;

typedef long long ll;

int main()
{
  //freopen("in", "r", stdin);
  ll a, b, c, N;
  cin >> N ;
  for (a = 1; a <= 3500; ++a) {
    for (b = 1; b <= 3500; ++b) {
      ll t1 = N * a * b;
      ll t2 = 4 * a * b - N * (a + b);
      if (t2 <= 0) continue;
      if (t1 % t2 == 0) {
        c = t1 / t2;
        cout << a << " " <<  b << " " << c << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
//Sum of Nth decimal places
#include<bits/stdc++.h>
using namespace std;

int main(){
  int a, b, n;
  while(cin>>a>>b>>n){
    int ans=0;
    for(int i=0; i<n; i++){
      a=10*(a%b);
      ans+=a/b;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

void call(int n) {
  rrep(i,n) {
    int x = i;
    if (x%3 == 0) {
      cout << " " << i;
    }
    else {
      while (x) {
        if (x%10 == 3) {
          cout << " " << i;
          break;
        }
        else {
          x /= 10;
        }
      }
    }
  }
  cout << endl;
}

int main () {
  int n = in();
  call(n);
  return 0;
}


Measured memory_bytes: 3128
#include <iostream>

using namespace std;

int main()
{

	int kurai_100;
	int kurai_10;
	int kurai_1;
	int number;
	int co;

	cin >> number;

	co = 0;

	if(number / 100 >= 1){
		kurai_100 = 1;
		co++;
	}
	else {
		kurai_100 = 0;
	}

	if ((number / 10)-(kurai_100*10) >= 1) {
		kurai_10 = 1;
		co++;
	}
	else {
		kurai_10 = 0;
	}

	if (number - (kurai_100 * 100) - (kurai_10 * 10) >= 1) {
		kurai_1 = 1;
		co++;
	}
	else {
		kurai_1 = 0;
	}

	cout << co;

    return 0;
}

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

using namespace std;

int a, b, c;

signed main() {
	cin >> a >> b;
	if(a > b) swap(a, b);
	for(c = a; c <= b; ++c)
		if(a*b*c%2 == 1) {
			cout << "Yes";
			return 0;
		}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int state = 0;
    int ans = 0;
    int prev = 0;
    for (int i = 0; i < N; i++) {
      int A = sc.nextInt();
      if (i == 0) {
        ans++;
      } else {
        if (state == 0) {
          if (prev < A) {
            state = 1;
          } else if (prev > A) {
            state = -1;
          }
        } else if (state > 0) {
          if (prev > A) {
            state = 0;
            ans++;
          }
        } else {
          if (prev < A) {
            state = 0;
            ans++;
          }
        }
      }
      prev = A;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 50292
#include<iostream>
using namespace std;
int main() {
    int n;
    char s[10];
    int k;
    cin >> n >> s >> k;
    for(int i=0;i<n;i++) {
        if(s[i] != s[k-1]) {
            cout << "*";
        }else if(s[i] == s[k-1]) {
            cout << s[i];
        }
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

const int MAX_N = 1000000;
bool prime[MAX_N];
void eratos() {
	for (int i = 0; i < MAX_N; ++i) prime[i] = true;
	prime[0] = prime[1] = false;
	for (int i = 2; i < sqrt(MAX_N); ++i) {
		if (prime[i]) {
			for (int j = 0; i * (j + 2) < MAX_N; ++j) {
				prime[i * (j + 2)] = false;
			}
		}
	}
}

int main() {
	eratos();
	int a, d, n;
	while (cin >> a >> d >> n, n) {
		int cnt = 0;
		if (prime[a]) cnt++;
		while (cnt < n) {
			a += d;
			if (prime[a]) cnt++;
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    else
    {
        return gcd(b,a%b);
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int A,B,C;
    cin>>A>>B>>C;
    int m=gcd(A,B);
   // cout <<m <<endl;
    if(C%m==0)
    {
        cout <<"YES"<<endl;
    }
    else
    {
        cout <<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete

era 0 n
  | n<=1911 = ('M':) $ show $ n - 1867
  | n<=1925 = ('T':) $ show $ n - 1911
  | n<=1988 = ('S':) $ show $ n - 1925
  | n<=2016 = ('H':) $ show $ n-1988
era 1 n = show $ 1867 + n
era 2 n = show $ 1911 + n
era 3 n = show $ 1925 + n
era 4 n = show $ 1988 + n

main = getInts >>= putStrLn . apply2 era



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15



int main() {
	ll n;
	cin >> n;
	vector<ll> a(n), b(n), c(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];
	for(int i = 0; i < n; i++)
		cin >> c[i];	
		
	sort(all(a));
	sort(all(c));
	
	ll cnt = 0;
	for(int i = 0; i < n; i++){
		ll cnt_a = lower_bound(all(a), b[i]) - a.begin();
		ll cnt_c = c.end() - upper_bound(all(c), b[i]);
		cnt += cnt_a * cnt_c;
	}
	
	cout << cnt << endl;
	return 0;
}





Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, b, c, ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a >> b >> c;
		for (int i = 0; i < 1200; i++) {
			if (a > 0 && b > 0 && c > 0) {
				a--; b--; c--; ans++;
			}
			else if (a > 1 && b > 0) {
				a--; a--; b--; ans++;
			}
			else if (a > 2) {
				a--; a--; a--; ans++;
			}
		}
		cout << ans << endl;
		ans = 0;
	}
	cin >> n;
}


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

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

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;
    int n;
    cin>>n;
    float pi =3.14159265359;
    cout<<float(2*pi*n)<<"\n";

}


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

int main(){
    int n,m;
    cin>>n>>m;
    int ans1,ans2;
    if(n>=2)
    ans1=n*(n-1)/2;
    else
    ans1=0;
    if(m>=2)
    ans2=m*(m-1)/2;
    else
    ans2=0;
    cout<<ans1+ans2<<endl;
    return 0;
}

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

using namespace std ;

int n, K ;

const int MAXN = 100010 ; 

int a[MAXN] ;

struct Edge {
		int l, r, nxt;
} e[MAXN << 1]; 

int ecnt = 0, hed[MAXN] ;

void addedge(int l, int r) {
		++ecnt, e[ecnt].l = l, e[ecnt].r = r, e[ecnt].nxt = hed[l], hed[l] = ecnt ;
}

int root = 0 ; 

int L[MAXN], R[MAXN], typ[MAXN] ;

bool flag = 1; 

void Dfs(int x, int fr) {
		L[x] = -1000000000, R[x] = 1000000000, typ[x] = -1 ;
		if (a[x] >= 0) {
			   typ[x] = (a[x] & 1) ; 
			   L[x] = R[x] = (a[x] >> 1);  
		}
		for (int i = hed[x]; i && flag; i = e[i].nxt) {
				int to = e[i].r ;
			    if (to ^ fr) {
						Dfs(to, x) ; 
						if (typ[to] >= 0) { 
								if (typ[to] == typ[x]) {
										flag = 0 ;
										return ; 
								}
								else {
										if (typ[to] == 0) {
												L[x] = max(L[x], L[to] - 1), R[x] = min(R[x], R[to]) ; 
										}
										else L[x] = max(L[x], L[to]), R[x] = min(R[x], R[to] + 1) ; 
								}
								typ[x] = typ[to] ^ 1 ; 
						}
				}
		}
		if (L[x] > R[x]) flag = 0 ;
}

void Dfs2(int x, int fr) {
			for (int i = hed[x]; i; i = e[i].nxt) {
					int to = e[i].r ;
					if (to != fr) { 
							if (L[to] <= (a[x] + 1) / 2 && (a[x] + 1) / 2 <= R[to]) a[to] = a[x] + 1 ;
							else a[to] = a[x] - 1; 
							Dfs2(to, x) ;
					}
			}
}

void Solve() {
		Dfs2(root, 0) ; 
		for (int i = 1; i <= n; i ++) printf("%d\n", a[i]) ;
}

int main() { 
#ifdef YJQ_LOCAL
		freopen(".in", "r", stdin) ;
#endif
		scanf("%d", &n) ;
		for (int i = 1; i < n; i ++) {
				int l, r ;
				scanf("%d%d", &l, &r); 
				addedge(l, r), addedge(r, l) ; 
		}
		scanf("%d", &K) ;
		memset(a, -1, sizeof a) ;
		for (int i = 1; i <= K; i ++) {
				int p, v;
				scanf("%d%d", &p, &v) ;
				a[p] = v ; 
				root = p ; 
		}
		Dfs(root, 0) ; 
		if (!flag) puts("No");
		else {
				puts("Yes") ;
				Solve() ;
		}
}




Measured memory_bytes: 9856
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n,k;
    cin >> k >> n;
    vector<ll>a(n),diff(n);
    REP(i,n)cin >> a[i];
    ll total = 0;
    
    REP(i,n-1){
        diff[i]=a[i+1]-a[i];
    }
    diff[n-1]=a[0]+k-a[n-1];
    REP(i,n){
        total += diff[i];
    }
    SORT(diff);
    
    cout << total - diff[n-1] << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include <stdlib.h>
int main (){
    int n;
    scanf("%d", &n);
    int a[n+2], b[n+2],l = 0;
    for (int i = 0; i < n; i++){
        scanf("%d %d", &a[i], &b[i]);
        l += (abs(a[i] - b[i]) + 1);
    }

    printf("%d\n", l);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <queue>

#define INF 1e9
#define MAX_H 1000
#define MAX_W 1000

using namespace std;

struct Cood {int x, y; };

int N;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

char field[MAX_H][MAX_W + 1];
int d[MAX_H][MAX_W + 1];
queue<Cood> q;
int h, w, n;
int total_time = 0;

void init_bfs() {
    queue<Cood> new_q;
    swap(q, new_q);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            d[i][j] = INF;
        }
    }
}
/* current position (y, x) with current power 'current' & last cheeese target is 'last' */
int bfs(int sy, int sx, int target, int last) {
    init_bfs();
    int next_y, next_x;
    q.push(Cood{sx, sy});
    d[sy][sx] = 0;

    while (q.size()) {
        Cood current = q.front(); q.pop();
        if (field[current.y][current.x] == '0' + target) {
            total_time += d[current.y][current.x];
            if (target == last) {
                return total_time;
            } else {
                return bfs(current.y, current.x, target + 1, last);
            }
        }

        for (int i = 0; i < 4; ++i) {
            next_y = current.y + dy[i];
            next_x = current.x + dx[i];
            if (0 <= next_y && next_y < h && 0 <= next_x && next_x < w
                && field[next_y][next_x] != 'X' && d[next_y][next_x] == INF) {
                q.push(Cood{next_x, next_y});
                d[next_y][next_x] = d[current.y][current.x] + 1;
            }
        }
    }
}

int main() {
    //freopen("0558_1.in", "r", stdin);
    cin >> h >> w >> n;
    int sx, sy;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> field[i][j];
            if (field[i][j] == 'S') {
                sy = i, sx = j;
            }
        }
    }
    total_time = 0; // init
    cout << bfs(sy, sx, 1, n) << endl;
    return 0;
}

Measured memory_bytes: 6104
var
	n,i,j,sto,ma,m,ans,vv:Longint;
	v,t:array[0..100]of Longint;
begin
	read(n);
	for i:=0 to n-1 do read(t[i]);
	for i:=0 to n-1 do read(v[i]);
	for i:=0 to n-1 do begin
		sto:=v[i+1];
		ma:=0;
		for j:=n-1 downto i+1 do begin
			if ma+t[j]>v[j] then ma:=v[j] else ma:=ma+t[j];
		end;
		v[i+1]:=ma;
		if v[i]<=v[i+1] then begin
			if v[i]-vv<=t[i] then begin
				ans:=ans+(v[i]-vv)*(v[i]+vv)*4+(t[i]-v[i]+vv)*v[i]*8;
				vv:=v[i];
			end else begin
				ans:=ans+t[i]*(vv*2+t[i])*4;
				vv:=vv+t[i];
			end;
		end else begin
			if v[i+1]-vv>t[i] then begin
				ans:=ans+t[i]*(vv*2+t[i])*4;
				vv:=vv+t[i];
			end else if v[i]-vv+v[i]-v[i+1]<=t[i]then begin
				ans:=ans+(v[i]-vv)*(v[i]+vv)*4+(v[i]-v[i+1])*(v[i]+v[i+1])*4+(t[i]-v[i]+vv-v[i]+v[i+1])*v[i]*8;
				vv:=v[i+1];
			end else begin
				m:=t[i]+vv+v[i+1];
				ans:=ans+(m-vv*2)*(m+vv*2)+(m-v[i+1]*2)*(m+v[i+1]*2);
				vv:=v[i+1];
			end;
		end;
		v[i+1]:=sto;
	end;
	writeln(ans/8:0:9);
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,D;cin>>N>>D;
  vector<vector<int>> a(N,vector<int>(D));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin>>a.at(i).at(j);
    }
  }
  
  int l,check,count=0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      l=0;
      check=0;
      for(int k=0;k<D;k++){
        l+=pow(a.at(i).at(k)-a.at(j).at(k),2);
      }
      check=sqrt(l);
      if(check*check==l)count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256