akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <ll>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(ll i=0;i<n;i++)
#define pb      push_back
const ll mod=1e9+7;
void fast();
int main()
{
    int n;
    cin>>n;
    ll a[n];
    int mx=-1e9,mn=1e9,x=0,y=0;
    loop(n){
        cin>>a[i];
        if(a[i]>mx)
            mx=a[i],x=i+1;
        if(a[i]<mn)
            mn=a[i],y=i+1;
    }
    vii res;
    if(mx+mn>0){
        for(int i=0;i<n;i++){
            if(a[i]<=0)
                res.pb({x,i+1});
        }
        for(int i=1;i<n;i++)
            res.pb({i,i+1});
    }
    else{
        for(int i=0;i<n;i++)
            if(a[i]>=0)
                res.pb({y,i+1});
        for(int i=n-2;i>=0;--i)
            res.pb({i+2,i+1});
    }
    cout<<res.size()<<endl;
    for(int i=0;i<res.size();i++)
        cout<<res[i].first<<" "<<res[i].second<<endl;
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/// 20
/// 15 7 13 15 15 15 15 13 19
/*

*/


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve(){
	while (true) {
		string a;
		cin >> a;
		if (a == "0") return;
		string b, c;
		cin >> b >> c;
		int dp[2] = {1,0};
		for (int i = b.length() - 1; i >= 0; --i) {
			int new_dp[2] = {};
			REP(q, 2) {
				REP(j, 10) {
					if (a[i] != '?' && a[i] - '0' != j) continue;
					if (i == 0 && j == 0) continue;
					REP(t, 10) {
						if (b[i] != '?' && b[i] - '0' != t) continue;
						if (i == 0 && t == 0) continue;
						int hoge = j + t + q;
						if (c[i] == '?' || c[i] - '0' == hoge % 10) {
							new_dp[hoge / 10] += dp[q];
						}
					}
				}
			}
			const int mod = 1000000007;
			REP(q, 2) {
				dp[q] = new_dp[q] % mod;
			}
		}
		cout << dp[0] << endl;
	}
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3144
// Vicfred
// https://atcoder.jp/contests/abc156/tasks/abc156_d
// math
import std.algorithm;
import std.stdio;
long mod = 10^^9+7;
const long maxn = 10^^6;

long[maxn+1] fac;
long[maxn+1] inv;
long[maxn+1] finv;

long C(long n, long k, long m) {
    if(n < 0 || n < k) return 0L;
    return (fac[n]%m * finv[k]%m * finv[n-k]%m)%m;
}

long H(long n, long k, long m) {
    if(n < 0 || k < 0) return 0L;
    return C(n+k-1, k, m);
}

void main() {
    long n, k;

    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for(long i = 2; i <= maxn; ++i) {
        fac[i] = fac[i-1]*i%mod;
        inv[i] = (mod - (mod/i) * inv[mod%i] % mod)%mod;
        finv[i] = finv[i-1]*inv[i]%mod;
    }

    readf("%s %s\n", &n, &k);

    long ans = 0;
    for(int i = 0; i < min(n, k+1); ++i) {
        ans += C(n, i, mod)*H(n-i, i, mod)%mod;
        ans %= mod;
    }

    ans.writeln;
}



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

map<ll, int> dict;


int main(){
  int N;
  cin >> N;
  ll a;
  for(int j =0 ; j<N; j++){
    cin >> a;
    if(dict.count(a) == 0){
      dict[a] = 1;
    }else{
      dict[a] = dict[a] +  1;
    }
  }
  ll count = 0;

  for(auto i = dict.begin(); i!=dict.end(); i++){
    if(i->first > i->second){
      // cout << i->first << "111";
      // cout << i->second << endl;
      count += i->second;

    }else if(i->first == i->second){
      // cout << i->first;
      // cout << "same" << endl;
    }else{
      // cout << i->first << "333";
      count += i->second - i->first;
    }
  }

  cout << count << endl;


}


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

int main() {
  int n, k;
  cin >> n >> k;
  
  int total = 0;
  for (int i = 0; i < n; i++) {
    int x, b;
    cin >> x;
    
    b = k > x ? k - x : x - k;
    b *= 2;
    x *= 2;

    if (x < b) {
      total += x;
    } else {
      total += b;
    }
  }

  cout << total << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main()
{
	int cnt = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
  uint32_t N = 0;
  std::cin >> N;
  std::vector<uint32_t> A(N + 1, 0);
  for (uint32_t i = 1; i < N + 1; i++) std::cin >> A[i];
  std::vector<bool> flag(N + 1, false);
  uint32_t at = 1;
  int32_t count = 0;
  while (!flag[at] && at != 2) {
    flag[at] = true;
    at = A[at];
    count++;
  }

  std::cout << (at == 2 ? count : -1) << std::endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N >> S;
  string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string ans;
   
  for(int i=0;i<S.size();i++){
    for(int j=0;j<26;j++){
      if(S.at(i)==alpha.at(j)){
        char x = alpha.at((j+N)%26);
        ans += x;
      }
    }
  }
    cout << ans << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

struct Point {
    int x, y;
}

void main() {
    while (true) {
        int N; readf("%d\n", &N);
        if (N == 0) break;
        auto P = new Point[N];
        auto A = new Point[4];
        foreach (ref p; P) { readf("%d %d\n", &p.x, &p.y); }
        foreach (ref p; A) { readf("%d %d\n", &p.x, &p.y); }
        auto X = (P.dup ~ A.dup).map!"a.x".array;
        auto Y = (P.dup ~ A.dup).map!"a.y".array;

        X = X.sort.uniq.array;
        Y = Y.sort.uniq.array;
        int[int] mX, mY;
        foreach (int i, x; X) mX[x] = i;
        foreach (int i, y; Y) mY[y] = i;
        auto H = Y.size;
        auto W = X.size;

        int ax = int.max, ay = int.max, bx = int.min, by = int.min;
        foreach (a; A) {
            ax = min(ax, a.x);
            ay = min(ay, a.y);
            bx = max(bx, a.x);
            by = max(by, a.y);
        }
        ax = mX[ax]; ay = mY[ay];
        bx = mX[bx]; by = mY[by];

        int area(int i, int j) {
            if (i + 1 == H || j + 1 == W) return 0;
            int sy = Y[i], ty = Y[i + 1];
            int sx = X[j], tx = X[j + 1];
            int dy = ty - sy;
            int dx = tx - sx;
            return dy * dx;
        }

        auto D = new int[][](H, W);
        int n = P.size;
        for (int i = 0; i < n; i++) {
            auto p = P[i], q = P[(i + 1) % n];
            auto s = Point(mX[p.x], mY[p.y]);
            auto t = Point(mX[q.x], mY[q.y]);
            if (s.y == t.y) continue;
            assert(s.x == t.x);
            int dy = (t.y - s.y) / abs(t.y - s.y);
            do {
                int y = s.y + (dy == -1 ? -1 : 0);
                D[y][s.x] = (dy == -1 ? 1 : -1);
                s.y += dy;
            } while (s != t);
        }
        long ans = 0;
        for (int i = 0; i < H; i++) {
            int d = 0;
            for (int j = 0; j < W; j++) {
                d += D[i][j];
                assert(0 <= d && d <= 1);
                if (! (ax <= j && j < bx && ay <= i && i < by) ) {
                    ans += d * area(i, j);
                }
            }
            assert(d == 0);
        }
        writeln(ans);

    }

}

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

int main(){
while(1){
	int n,m,pi;
	vector<int> x,p;

	scanf("%d%d",&n,&m); if(n==0&&m==0)break;
	for(int i=0;i<n;i++){
		scanf("%d",&pi);
		p.push_back(pi);
	}
	p.push_back(0);

	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			x.push_back(p[i]+p[j]);
		}
	}

	sort(x.begin(),x.end());
	int ret=0;
	for(int i=0;i<n*n+2*n+1;i++){
		int t=upper_bound(x.begin(),x.end(),m-x[i])-x.begin();
		if(t>0)ret=max(ret,x[i]+x[t-1]);
	}

	printf("%d\n",ret);
}
}

Measured memory_bytes: 9164
# ABC089C - March
import sys
input = sys.stdin.readline

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip()[0] for _ in range(n)]
    cand = [lst.count(s) for s in "MARCH"]
    ans = sum(x * y * z for x, y, z in combinations(cand, 3))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3884
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
b = 2 ** 60
ret = 0
while b > 0:
    c0, c1 = 0, 0
    for ai in a:
        if ai & b != 0:
            c1 += 1
        else:
            c0 += 1
    ret = (ret + c1 * c0 * b) % mod
    b //= 2
print(ret)

Measured memory_bytes: 122808
using System;

namespace A___ι_l
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var a = int.Parse (input[0]);
            var b = int.Parse (input[1]);
            var c = int.Parse (input[2]);
            if (b - a == c - b)
            {
                Console.WriteLine ("YES");
            }
            else
            {
                Console.WriteLine ("NO");
            }
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}
/**

**/


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
  static class Pair {
    int left;
    int right;
    int depth;

    Pair(int l, int r, int depth) {
      left = l;
      right = r;
      this.depth = depth;
    }
  }

  public static void main(String[] args) {
    Scanner std = new Scanner(System.in);
    int h = std.nextInt();
    int w = std.nextInt();
    char[][] table = new char[h][w];
    for (int i = 0; i < h; i++) {
      String line = std.next();
      for (int j = 0; j < w; j++) {
        char c = line.charAt(j);
        table[i][j] = c;
      }
    }

    int max = 0;

    Deque<Pair> deque = new ArrayDeque<>();
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (table[i][j] == '#') {
          continue;
        }

        Pair start = new Pair(i, j, 0);
        boolean[][] visited = new boolean[h][w];

        deque.add(start);
        while (!deque.isEmpty()) {
          Pair p = deque.poll();
          max = Math.max(p.depth, max);
          if (visited[p.left][p.right]) {
            continue;
          }

          visited[p.left][p.right] = true;
          int left = p.right - 1;
          int right = p.right + 1;
          int top = p.left - 1;
          int bottom = p.left + 1;

          if (left >= 0) {
            char c = table[p.left][left];
            if (c != '#' && !visited[p.left][left]) {
              deque.add(new Pair(p.left, left, p.depth + 1));
            }
          }

          if (right < table[0].length) {
            char c = table[p.left][right];
            if (c != '#' && !visited[p.left][right]) {
              deque.add(new Pair(p.left, right, p.depth + 1));
            }
          }

          if (top >= 0) {
            char c = table[top][p.right];
            if (c != '#' && !visited[top][p.right]) {
              deque.add(new Pair(top, p.right, p.depth + 1));
            }
          }

          if (bottom < table.length) {
            char c = table[bottom][p.right];
            if (c != '#' && !visited[bottom][p.right]) {
              deque.add(new Pair(bottom, p.right, p.depth + 1));
            }
          }
        }
      }
    }

    System.out.println(max);
  }
}


Measured memory_bytes: 30004
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007

ll dp[101][100001];

signed main(){
    //ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n,c;
    int w,v;
    cin>>n>>c;

    
    f0(i,0,n)
        f0(j,0,100001){
            dp[i][j]=INT_MAX;
        }
    
    
    cin>>w>>v;
    dp[0][v]=w;

    f0(i,1,n){
        cin>>w>>v;
        dp[i][v]=w;
        f0(j,0,100001){
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
            if(j-v>=0) dp[i][j]=min(dp[i][j],dp[i-1][j-v]+w);
        }
    }

    f3(i,100000,0){
        if(dp[n-1][i]<=c){
            cout<<i;
            break;
        }
    }
}

Measured memory_bytes: 78336
class Restaurant:
    def __init__(self, i, s, p):
        self.i, self.s, self.p = i, s, p


N = int(input())
restaurants = []
for i in range(1, N + 1):
    s, p = input().split(" ")
    restaurants.append(Restaurant(i, s, int(p)))

restaurants.sort(key=lambda x: x.p, reverse=True)
restaurants.sort(key=lambda x: x.s)

for r in restaurants:
    print(r.i)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int kaz=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='+'){
      kaz++;
    }else{
      kaz--;
    }
  }
  cout << kaz << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int a,b;
  cin>>a;
  b=a%100;
  a=a-b;
  a/=100;
  if(1<=b&&b<=12){
    if(1<=a&&a<=12){
      cout<<"AMBIGUOUS"<<endl;
    }else{
      cout<<"YYMM"<<endl;
    }
  }else if(1<=a&&a<=12){
    cout<<"MMYY"<<endl;
  }else{
    cout<<"NA"<<endl;
  }
}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define line puts("-------");
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
int n,m;
int cost[N][N];
bool vis[N][N];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
string a[N];
bool valid(int x,int y)
{
    return x>=0 && x<n && y>=0 && y<m && a[x][y]=='.' && !vis[x][y];
}
int bfs(int u,int v)
{
    memb(vis);
    mem(cost,0);
    queue<pi>q;
    q.push({u,v});
    vis[u][v]=true;
    cost[u][v]=0;
    int i,j,ans=0;
    while(!q.empty())
    {
        pi p=q.front();
        q.pop();
        int x,y,xx,yy;
        x=p.fi,y=p.se;
        rep0(i,4)
        {
            xx=x+dx[i];
            yy=y+dy[i];
            if(valid(xx,yy))
            {
                vis[xx][yy]=true;
                cost[xx][yy]=cost[x][y]+1;
                q.push({xx,yy});
            }
        }
    }
    rep0(i,n)
    {
        rep0(j,m)
            ans=max(ans,cost[i][j]);
    }
    return ans;
}
int main()
{
    memb(vis);
    mem(cost,0);
    cin>>n>>m;
    int i,j,ans=0;
    rep0(i,n)
        cin>>a[i];
    rep0(i,n)
    {
        rep0(j,m)
        {
            if(a[i][j]=='.')
                ans=max(ans,bfs(i,j));
        }
    }
    cout<<ans;
}
/*
3 3
###
#..
##.
*/


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

int main() {
  int N;
  int d[70];
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> d[i];
  int total = 0;
  
    for (int b = 0; b < N - 1; ++b) {
      for (int c = b + 1; c < N; ++c) {
        if(b != c){
        total += d[b] * d[c]; // 合計値
        }
      }
    }
  
  cout << total << endl;
}


Measured memory_bytes: 256
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		FScanner fs=new FScanner();
		//Scanner sc=new Scanner(System.in);
		
		String[] s=fs.readStringL();
		boolean slv=true;
		
		if(!s[0].equals("A")){
			slv=false;
		}
		
		if(s[1].equals(s[1].toUpperCase())){
			slv=false;
		}
		if(s[s.length-1].equals(s[s.length-1].toUpperCase())){
			slv=false;
		}
		
		int cntC=0;
		
		for(int i=2; i<s.length-1; i++){
			if(s[i].equals("C")){
				cntC+=1;
			}else if(s[i].equals(s[i].toUpperCase())){
				slv=false;
			}
		}
		
		if(cntC!=1){
			slv=false;
		}
		
		System.out.println(slv==true? "AC": "WA");
		
	}

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
	
	static class FScanner{
		Scanner sc;
		FScanner() throws FileNotFoundException{
			sc=new Scanner(System.in);
		}
		int readInt(){
			int i=Integer.parseInt(sc.nextLine());
			return i;
		}
		String[] readStringL(){
			String[] s=sc.nextLine().split("");
			return s;
		}
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[110];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i);
        if(a[i]%2==0)
        {
            if(a[i]%3!=0&&a[i]%5!=0)
            {
                printf("DENIED");
                return 0;
            }
        }
    }
    printf("APPROVED");
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a%3==0||b%3==0||(a+b)%3==0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	char s[15];
	cin>>s;
	int i,len,cont=0,sum=0,num;
	len=strlen(s);
	if(s[0]!='A') printf("WA");
	else 
	{
		for(i=2;i<(len-1);i++)
		if(s[i]=='C') cont++;
		if(cont!=1) printf("WA");
		else
		{
			for(i=0;i<len;i++)
			{
				if(s[i]<='z'&&s[i]>='a')
					sum++;
				if(s[i]=='A'||s[i]=='C')
					num++;
			}
			if((sum+num)==len) printf("AC");
			else printf("WA");
			
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
edge = [set() for i in range(N+1)]
for i in range(N-1):
  a, b = map(int, input().split())
  edge[a].add((b, i))
  edge[b].add((a, i))

r = [0] * (N - 1)
q = deque([(0, 1)])

while q:
  preC, fromv = q.popleft()
  c = 0
  for tov, i in edge[fromv]:
    edge[tov].remove((fromv, i))
    c += 1 + (c + 1 == preC)
    q.append((c, tov))
    r[i] = c
print(max(r))
for x in r:
  print(x)

Measured memory_bytes: 51784
#include<cstdio>
using namespace std;

int h,w;
char field[105][105];
int main(){
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;++i) scanf("%s",field[i]);
	for(int i=0;i<h;++i){
		int lastPos=-1;
		for(int j=0;j<w;++j){
			if(field[i][j]=='c') lastPos=j;
			
			int res=-1;
			if(lastPos!=-1) res=j-lastPos;
			printf("%d%c",res,j==w-1?'\n':' ');
		}
	}

	return 0;
}





Measured memory_bytes: 2768
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y;
	cin>>n>>x>>y;
	int a[n];
	for(int i=1;i<=n-1;i++)
	  a[i]=0;
	for(int i=1;i<=n;i++)
	  for(int j=i+1;j<=n;j++)
	    a[min(min(abs(j-i),abs(i-x)+1+abs(j-y)),abs(i-y)+1+abs(j-x))]++;
	for(int i=1;i<=n-1;i++)
	  cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
  	int dp[];
  	Main(int n){
      dp = new int[n];
      for(int i = 0; i < dp.length; i++) {
    dp[i] = -1;
}
    }
	public static void main (String[] args) throws java.lang.Exception
	{
      	FastReader s = new FastReader();
		int  n = s.nextInt();
      	int k = s.nextInt();
		int arr[] = new int[n];
		for(int i=0;i<n;i++)
		arr[i]= s.nextInt();
		Main ob = new Main(n);
		k = Math.min(k,n-1);
		int ans = ob.getCost(n-1,arr,k);
		System.out.println(ans);
	}
  int getCost(int n,int arr[], int k){
    if(dp[n]!=-1) return dp[n];
  	if(n==0){
    dp[0]=0;
      return 0;
    }
    if(n==1){
      dp[1]= Math.abs(arr[1]-arr[0]);
      return dp[1];
    }
    int ans= Integer.MAX_VALUE;
    for(int i = 1;i<=k&&n-i>=0;i++)
      ans = Math.min(ans,Math.abs(arr[n]-arr[n-i])+getCost(n-i,arr,Math.min(k,n-i)));
      dp[n] = ans;
    return dp[n];
  }


  static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 49972
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> d1(n);
    vector<int> d2(n);

    for(int i=0;i<n;i++)
    cin>>d1[i]>>d2[i];
    bool flag=false;
    for(int i=0;i<n-2;i++){
        if(d1[i]==d2[i] && d1[i+1]==d2[i+1] && d1[i+2]==d2[i+2]){
            cout<<"Yes\n";
            flag=true;
            break;
        }
    }
    if(!flag)
    cout<<"No\n";
    
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin>>s;
  int n=s.size();

  ll dp[n+1],next[n+1][27];

  for(int i=0;i<=n;i++){
    dp[i]=1e8;
    for(int j=0;j<=26;j++){
      next[i][j]=n;
    }
  }

  for(int i=n-1;i>=0;i--){
    for(int j=0;j<26;j++){
      next[i][j]=next[i+1][j];
      next[i][s[i]-'a']=i;
    }
  }

  dp[n]=1;
  for(int i=n-1;i>=0;i--){
    for(int j=0;j<26;j++){
      if(next[i][j]==n) dp[i]=1ll;
      else dp[i]=min(dp[i],dp[next[i][j]+1]+1);
    }
  }

  string ans="";
  int it=0;
  while(ans.size()<dp[0]){
    for(int j=0;j<26;j++){
      if(next[it][j]==n){
        ans=ans+(char)('a'+j);
        break;
      }
      if(dp[it]==dp[next[it][j]+1]+1){
        ans=ans+(char)('a'+j);
        it=next[it][j]+1;
        break;
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


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

int main(){
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<long long> A(X);
  vector<long long> B(Y);
  vector<long long> C(Z);
  for(int i=0; i<X; i++) cin >> A.at(i);
  for(int i=0; i<Y; i++) cin >> B.at(i);
  for(int i=0; i<Z; i++) cin >> C.at(i);
  vector<long long> AB(X*Y);
  int k=0;
  for(int i=0; i<X; i++){
    for(int j=0; j<Y; j++){
      AB.at(k)=A.at(i)+B.at(j);
      k++;
    }
  }
  sort(AB.begin(),AB.end());
  reverse(AB.begin(),AB.end());
  
  vector<long long> ABC(min(3000,X*Y)*Z);
  int l=0;
  for(int i=0; i<min(3000,X*Y); i++){
    for(int j=0; j<Z; j++){
      ABC.at(l)=AB.at(i)+C.at(j);
      l++;
    }
  }
  sort(ABC.begin(),ABC.end());
  reverse(ABC.begin(),ABC.end());

  for(int i=0; i<K; i++) cout << ABC.at(i) << endl;  
}


Measured memory_bytes: 31616
//1.read question_2.read I/O_3.read test cases_4.read constraints(to decide TC of solution)_5.decide method_6.dry run_
//7.code_8.test_9.submit
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define _READ freopen("input.txt","r", stdin);
#define pb push_back
#define MP make_pair
#define _FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
vector<lli> edges[100001];
lli visited[100001];
lli len[100001];
int dfs(lli i)
{
    visited[i]=1;
    for(auto j:edges[i])
    {
        if(visited[j]==0)
        {
            len[j]=dfs(j);
            len[i]=max(len[i],len[j]+1);
        }
        else
        {
            len[i]=max(len[i],len[j]+1);
        }
    }
    return len[i];
}
int main()
{
    
    _FAST
    lli n,t,i,j,k,ans=0,flag=0,a,b,m;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a>>b;
        edges[a].pb(b);
    }
    for(i=1;i<=n;i++)
        edges[0].pb(i);
    cout<<dfs(0)-1;
    return 0;
}


Measured memory_bytes: 10228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k; 
    cin>>n>>k;
    vector<ll> a(n);
    ll ma=0;
    rep(i,n){
      cin>>a[i];
      ma=max(ma,a[i]);
    }
    ll ret=a[0];
    rep(i,n) ret=gcd(ret,a[i]);
    //cout<<ret<<' '<<ma<<endl;
    if(k<=ma && k%ret==0) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}


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

class lowest_common_ancestor {
	using pii = pair<int, int>;
	vector<int> depth, par, heavy, head;
	int dfs(int v, int prev, const graph& G) {
		par[v] = prev;
		depth[v] = prev != -1 ? depth[prev] + 1 : 0;
		int ma = 0, cnt = 1;
		for (auto to : G[v]) if (to != prev) {
			int c = dfs(to, v, G);
			if (c > ma) {
				ma = c;
				heavy[v] = to;
			}
			cnt += c;
		}
		return cnt;
	}
public:
	lowest_common_ancestor(const graph& G, int rt = 0)
		: depth(G.size()), par(G.size()), heavy(G.size(), -1), head(G.size()) {
		dfs(rt, -1, G);
		queue<int> q;
		q.push(rt);
		while (!q.empty()) {
			int h = q.front(); q.pop();
			for (int v = h; v != -1; v = heavy[v]) {
				head[v] = h;
				for (auto to : G[v]) if (to != par[v] && to != heavy[v]) {
					q.push(to);
				}
			}
		}
	}
	int calc(int u, int v) {
		while (head[u] != head[v]) {
			if (depth[head[u]] < depth[head[v]]) v = par[head[v]];
			else u = par[head[u]];
		}
		return depth[u] < depth[v] ? u : v;
	}
	int dist(int a, int b) {
		return depth[a] + depth[b] - depth[calc(a, b)] * 2;
	}
};

const int MAX = 1e5;
int dep[MAX];
int vv[MAX];
int lv[MAX], rv[MAX];
int vit;

void euler_tour(int v, int prev, const graph& G) {
	dep[vit] = prev == -1 ? 0 : dep[prev] + 1;
	vv[vit] = v;
	lv[v] = vit++;
	for (auto to : G[v]) if (to != prev) {
		euler_tour(to, v, G);
	}
	rv[v] = vit;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	graph G(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v; --u, --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	lowest_common_ancestor lc(G);
	euler_tour(0, -1, G);
	vector<set<int>> vs(MAX);
	vector<int> res(MAX, -1);
	auto add = [&](int v, int c) {
		if (vs[c].empty()) {
			vs[c].insert(lv[v]);
			res[c] = 0;
			return;
		}
		auto it = vs[c].lower_bound(lv[v]);
		int pre = vv[it == vs[c].begin() ? *vs[c].rbegin() : *prev(it)];
		int nex = vv[it == vs[c].end() ? *vs[c].begin() : *it];
		vs[c].insert(lv[v]);
		res[c] += (lc.dist(pre, v) + lc.dist(v, nex) - lc.dist(pre, nex)) / 2;
	};
	auto del = [&](int v, int c) {
		vs[c].erase(lv[v]);
		if (vs[c].empty()) {
			res[c] = -1;
			return;
		}
		auto it = vs[c].lower_bound(lv[v]);
		int pre = vv[it == vs[c].begin() ? *vs[c].rbegin() : *prev(it)];
		int nex = vv[it == vs[c].end() ? *vs[c].begin() : *it];
		res[c] -= (lc.dist(pre, v) + lc.dist(v, nex) - lc.dist(pre, nex)) / 2;
	};
	vector<int> c(n);
	for (int i = 0; i < n; i++) {
		cin >> c[i]; --c[i];
		add(i, c[i]);
	}
	int m;
	cin >> m;
	while (m--) {
		char com;
		cin >> com;
		if (com == 'U') {
			int x, y;
			cin >> x >> y; --x, --y;
			del(x, c[x]);
			add(x, y);
			c[x] = y;
		}
		else {
			int y;
			cin >> y; --y;
			printf("%d\n", res[y]);
		}
	}
	return 0;
}



Measured memory_bytes: 27708
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> p(n),q(n),a(n);
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=0;i<n;i++)cin>>q[i];
    for(int i=0;i<n;i++)a[i]=i+1;
    int x,y,cnt=0;
    do{
        cnt++;
        bool P=true,Q=true;
        for(int i=0;i<n;i++){
            if(a[i]!=p[i])P=false;
            if(a[i]!=q[i])Q=false;
        }
        if(P)x=cnt;
        if(Q)y=cnt;
    }while(next_permutation(All(a)));
    cout<<abs(x-y)<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
typedef pair<int, int> ii;
void solve();
int main(int argc, char const *argv[]){
 	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    solve();
}
void solve(){
  int N;
  cin>>N;
  cout<<N/2 + (N%2)<<endl;
}


Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	REP(i, a+1){
		REP(j, b+1){
			int z = x - 500 * i - 100 * j;
			if(z >= 0 && z % 50 == 0 && z / 50 <= c) ans ++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int d[1004][1004];
string str[1004];
bool mrk[1004][1004];
priority_queue<pii,vector<pii >,greater<pii > > q;

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

	int n,m,x,y,i,j,sx,sy,tx,ty;

	cin >> n >> m;
	cin >> sx >> sy;
	cin >> tx >> ty;
	sx--;
	sy--;
	tx--;
	ty--;

	for(i=0;i<n;++i)
		cin >> str[i];

	for(i=0;i<n;++i)
		for(j=0;j<m;++j)
			d[i][j] = 1e9;

	d[sx][sy] = 0;
	q.push(pii(0,pi(sx,sy)));

	while(!(q.empty()))
	{
		pii ed = q.top();
		x = ed.ss.ff;
		y = ed.ss.ss;
		q.pop();
		if(mrk[x][y] == 1)
			continue;
		// cout << x << " " << y << " " << d[x][y] << endl;
		mrk[x][y] = 1;

		for(i=-1;i<=1;++i)
		{
			for(j=-1;j<=1;++j)
			{
				if(abs(i)==abs(j))
					continue;
				sx = x+i;
				sy = y+j;
				if(sx<0 || sx>=n || sy<0 || sy>=m)
					continue;
				if(str[sx][sy] == '#')
					continue;
				if(d[sx][sy]>d[x][y])
				{
					d[sx][sy] = d[x][y];
					q.push(pii(d[sx][sy],pi(sx,sy)));
				}
			}
		}


		for(i=-2;i<=2;++i)
		{
			for(j=-2;j<=2;++j)
			{
				sx = x+i;
				sy = y+j;
				if(sx<0 || sx>=n || sy<0 || sy>=m)
					continue;
				// cout << sx << " " << sy << endl;
				if(str[sx][sy] == '#')
					continue;
				if(d[sx][sy]>d[x][y]+1)
				{
					d[sx][sy] = d[x][y]+1;
					q.push(pii(d[sx][sy],pi(sx,sy)));
				}
			}
		}
	}

	if(d[tx][ty] > 1e8)
		cout << -1 << "\n";
	else
		cout << d[tx][ty] << "\n";
}
	


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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class BOneClue {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int k, x; cin >> k >> x;
      for(int i=-1000; i<=1000; i++) {
        if (x-(k-1) <= i && i <= x+(k-1)) {
          cout << i << ' ';
        }
      }
      cout << endl;
    }
};

signed main() {
  BOneClue solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
	public static void main(String[] args){
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
				PrintWriter pw = new PrintWriter(System.out);) {
			int m = Integer.parseInt(br.readLine());
			pw.println(48 - m);
			pw.flush();
		} catch (IOException e) {
		}
	}
}

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

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

  int max_move = 0;
  int move = 0;
  int prev_height = 0;
  
  for (int i = 0; i < n; ++i) {
    int height;
    cin >> height;
    if (height <= prev_height) {
      ++move;
      max_move = max(max_move, move);
    } else {
      move = 0;
    }
    prev_height = height;
  }
  cout << max_move << endl;
}


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

#define KAISU 15000

int inD;
int c[27] = {0};
int s[366][27] = {0};
int t[366] = {0};
int last[366] = {0};
long long int man = 0;

long long int cal_manzoku(void);
void input_A(void);
void input_t(void);
long long int exec_query(int &d, int &q);
void print_t(void);

int main(){

    srand((unsigned) time(NULL));

    input_A();
    // input_t();
    for(auto i=1; i<=inD; ++i){
        t[i] = rand() % 26 + 1;
    }
    man = cal_manzoku();
    // printf("%lld\n", man);

    for(auto i=0; i<KAISU; ++i){
        int rand_day = rand()%365 + 1;
        int rand_t = rand()%26 + 1;
        int t_pre = t[rand_day];
        long long man_pre = man;

        t[rand_day] = rand_t;
        man = cal_manzoku();
        if(man_pre > man){
            t[rand_day] = t_pre;
        }

    }
    print_t();

    // int m;
    // scanf("%d", &m);
    // for(int i=1; i<=m; ++i){
    //     int d,q;
    //     scanf("%d %d", &d, &q);
    //     man = exec_query(d, q);
    //     print_t();
    //     printf("%lld\n", man);
    // }

}

void print_t(void){
    for(int i=1; i<=inD; ++i){
        printf("%d\n", t[i]);
    }
    // printf("\n");
}

void input_A(){
    scanf("%d", &inD);
    for(int i=1; i<=26; ++i){
        scanf("%d", &c[i]);
    }
    
    // // Test
    // for(int i=1; i<=26; ++i){
    //     printf("%d ", c[i]);
    // }
    // printf("\n\n");

    for(int i=1; i<=inD; ++i){
        for(int j=1; j<=26; ++j){
            scanf("%d", &s[i][j]);
        }
    }
    // // Test
    // for(int i=1; i<=inD; ++i){
    //     for(int j=1; j<=26; ++j){
    //         printf("%d ", s[i][j]);
    //     }
    //     printf("\n");
    // }
    // printf("\n\n");

    return;
}

void input_t(){

    // 問題B入力
    for(int i=1; i<=inD; ++i){
        scanf("%d", &t[i]);
    }

    // // Test
    // for(int i=1; i<=inD; ++i){
    //     printf("%d ", t[i]);
    // }
    // printf("\n\n");
}

long long int cal_manzoku(){

    long long int manzoku=0;

    for(int day=1; day<=inD; ++day){
        long long int down = 0;
        last[t[day]] = day;
        for(int i=1; i<=26; ++i){
            down += c[i]*(day - last[i]);
            // printf("down %d %lld %d %d\n", day, down, c[i], last[i]);
        }

        manzoku = manzoku + s[day][t[day]] - down;
        // printf("manzoku %d %d %lld %d %lld\n", day, t[day], manzoku, s[day][t[day]], down);
        // printf("last %d %d\n", t[day], last[t[day]]);

        // printf("%lld\n", manzoku);
    }

    return(manzoku);

}

Measured memory_bytes: 1776
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))



//*
//遅延セグ木ここから
//↓ここを変える
typedef struct sayouso{ll a,b;}sayouso;
typedef struct atai{ll a;}atai;
//↑ここを変える

typedef struct node{sayouso T;atai x;}node;
node *lsegN,*lseg;
ll lsegNUM,lsegk;

//↓ここから変える
sayouso sid={1,0};
atai aid={(1LL<<31)-1};
atai xx(atai x,atai y){
	atai ret;
	ret.a=min(x.a,y.a);
	return ret;
}
atai Tx(sayouso T,atai x){
	atai ret;
	ret.a=T.a*x.a+T.b;
	return ret;
}
sayouso TT(sayouso S,sayouso T){
	sayouso ret;
	ret.a=S.a*T.a;
	ret.b=S.b+S.a*T.b;
	return ret;
}
sayouso fT(sayouso T,ll k){
	sayouso ret;
	ret.a=T.a;
	ret.b=T.b;
	return ret;
}
//↑ここまで変える

//要素数(2ベキ)でこれを呼ぶ
void lseguse(ll n){
	lsegN=(node*)calloc(2*n,sizeof(node));
	lsegNUM=n;
	lseg=lsegN+lsegNUM;
	lsegk=0;while(n/=2)lsegk++;
	rep(i,1,2*lsegNUM){
		lsegN[i].x=aid;
		lsegN[i].T=sid;
	}
}
//lseg[i].xに値を与えてから初期化
void lseginit(){
	for(ll i=lsegNUM-1;i>0;i--)lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
}
void lsegupdatesub(ll l,ll r,sayouso T,ll i,ll cl,ll cr,ll ck){
	if(l>=r)return;
	//disjointなとき
	if(cr<=l||r<=cl)return;
	//完全に含むとき
	if(l<=cl&&cr<=r){
		lsegN[i].T=TT(T,lsegN[i].T);
		return;
	}
	//どちらでもないとき
	//遅延伝播
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	//再帰的に更新
	ll cm=(cl+cr)/2;
	lsegupdatesub(l,r,T,2*i  ,cl,cm,ck-1);
	lsegupdatesub(l,r,T,2*i+1,cm,cr,ck-1);
	//自身のnodeを更新
	lsegN[i].x=xx(Tx(fT(lsegN[2*i].T,ck-1),lsegN[2*i].x),Tx(fT(lsegN[2*i+1].T,ck-1),lsegN[2*i+1].x));
	lsegN[i].T=sid;
}
void lsegupdate(ll l,ll r,sayouso T){lsegupdatesub(l,r,T,1,0,lsegNUM,lsegk);}
atai lsegcalcsub(ll l,ll r,ll i,ll cl,ll cr,ll ck){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return Tx(fT(lsegN[i].T,ck),lsegN[i].x);

	ll cm=(cl+cr)/2;
	//遅延伝播(変更はないので配るだけで良い)
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	lsegN[i].x=Tx(fT(lsegN[i].T,ck),lsegN[i].x);
	lsegN[i].T=sid;

	//左側だけ
	if(r<=cm)return lsegcalcsub(l,r,2*i  ,cl,cm,ck-1);
	//右側だけ
	if(cm<=l)return lsegcalcsub(l,r,2*i+1,cm,cr,ck-1);
	//両方
	return xx(lsegcalcsub(l,r,2*i,cl,cm,ck-1),lsegcalcsub(l,r,2*i+1,cm,cr,ck-1));
}
atai lsegcalc(ll l,ll r){return lsegcalcsub(l,r,1,0,lsegNUM,lsegk);}
//遅延セグ木ここまで
//*/


int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	lseguse(1<<17);
	while(q--){
		int t;
		scanf("%d",&t);
		if(t){
			int x,y;
			scanf("%d%d",&x,&y);
			printf("%lld\n",lsegcalc(x,y+1).a);
		}
		else{
			int x,y,b;
			scanf("%d%d%d",&x,&y,&b);
			sayouso T={0,b};
			lsegupdate(x,y+1,T);
		}
	}
}


Measured memory_bytes: 8004
N,Q=gets.split.map &:to_i
A=[1,c=1,1,*[0]*(N-2),1]
Q.times{
	a,b=gets.split.map &:to_i
	A[a],A[b]=A[b],A[a]
	c = c==a ? b : c==b ? a : c
	A[c-1]=A[c+1]=1
}
p A.reduce(:+)-2

Measured memory_bytes: 4092
#include <algorithm>
#include <array>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

constexpr int INF = 1000000000 + 8;

int manhattanDist(complex<int> x1, complex<int> x2) {
    return abs(x1.real() - x2.real()) + abs(x1.imag() - x2.imag());
}

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

    int n, m;
    cin >> n >> m;
    vector<complex<int>> students, checkpoints;
    students.reserve(n);
    checkpoints.reserve(m);

    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        students.push_back({a, b});
    }

    for (int i = 0; i < m; i++) {
        int c, d;
        cin >> c >> d;
        checkpoints.push_back({c, d});
    }

    for (int i = 0; i < n; i++) {
        const auto student = students[i];
        int shortest = INF;
        int shortest_i;

        for (int j = m - 1; j >= 0; j--) {
            const int dist = manhattanDist(student, checkpoints[j]);
            if (dist <= shortest) {
                shortest = dist;
                shortest_i = j;
            }
        }

        cout << shortest_i + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <limits>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <queue>

#define MAX 100009
#define INF 99999999
#define in(a,b)  ( (b).find(a) != (b).end())
#define clr(a,b) memset((a), (b), sizeof((a)))
#define pb       push_back
#define all(a)   a.begin(), a.end()  
#define mp       make_pair
#define ll	long long
#define fi	first
#define se second

const long double pi = 3.141592653589793238L;
const ll mod = 1e9 + 7;

/**
*
* @Author Lahia omar
*/

using namespace std;
void split(vector<string> &v, string cur) {
	istringstream iss(cur);
	copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter(v));
}
int a, b, c;

int main(int argc, char* argv[]) {
	
	cin >> a >> b >> c;
	cout << min(a+b,min(a+c,c+b)) << endl;
		
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define DEBUG(x) cerr << #x << ": " << x << "\n"

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_N = 40;
    const long INF = 1 << 20;
    int N;
    ll W, v[MAX_N], w[MAX_N];
    vector<pair<ll, ll> > p;  // (weight, value)
    cin >> N >> W;
    REP(i, N) {
        cin >> v[i] >> w[i];
    }
    int N2 = N / 2;
    REP(i, 1 << N2) {
        ll sw = 0, sv = 0;
        REP(j, N2) {
            if (i >> j & 1) {
                sw += w[j];
                sv += v[j];
            }
        }
        p.push_back(make_pair(sw, sv));
    }
    SORT(p);
    int m = 1;
    FOR(i, 1, 1 << N2) {
        if (p[m - 1].second < p[i].second) {
            p[m] = p[i];
            ++m;
        }
    }
    ll res = 0;
    REP(i, 1 << (N - N2)) {
        ll sw = 0, sv = 0;
        REP(j, N - N2) {
            if (i >> j & 1) {
                sw += w[N2 + j];
                sv += v[N2 + j];
            }
        }
        if (sw <= W) {
            pair<ll, ll> _p = make_pair(W - sw, INF);
            ll tv = (lower_bound(p.begin(), p.begin() + m, _p) - 1)->second;
            res = max(res, sv + tv);
        }
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 19408
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;

vector<vector<int>> v(10, vector<int>(10, 0));

int modpow(int n, int a) {
	int res = 1;
	while (a > 0) {
		if (a & 1) res = (res * n) % MOD;
		n = (n * n) % MOD;
		a >>= 1;
	}
	return res;
}

int gcd(int x, int y) {
	if (x < y) swap(x, y);
	if (y == 0)return x;
	else return gcd(y, x % y);
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k, x; cin >> k >> x;
	if (k * 500 >= x)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

v_cnt = 0
for l in range(1, N+1):
    v_cnt += (N-l+2)*(N-l+1)//2
e_cnt = 0
for _ in range(N-1):
    u, v = map(int, input().split())
    e_cnt += min(u, v)*(N-max(u, v)+1)
print(v_cnt-e_cnt)


Measured memory_bytes: 9188