akhauriyash/Code-Regression huggingface dataset:
# D - Wizard in Maze
import sys
from collections import deque
from typing import List, Tuple


class WarpableMaze:
    __slots__ = ["height", "width", "unsearched", "dist"]

    def __init__(
        self, height: int, width: int, grid: List[bytes], road: str = ".",
    ) -> None:
        self.height = height + 4
        self.width = width + 4
        self.unsearched = 1 << 30
        self.dist = self._convert_grid_to_dist(grid, road)

    def _convert_grid_to_dist(self, grid: List[bytes], road: str) -> List[int]:
        dist = [-1] * self.height * self.width
        i = self.width * 2 + 1
        for row in grid:
            for c in row.decode():
                i += 1
                if c == road:
                    dist[i] = self.unsearched
            i += 4
        return dist

    def _flatten_coordinate(self, x: int, y: int) -> int:
        return self.width * (x + 1) + y + 1

    def bfs(self, start_2d: Tuple[int, int], goal_2d: Tuple[int, int]) -> int:
        start = self._flatten_coordinate(*start_2d)
        goal = self._flatten_coordinate(*goal_2d)

        w = self.width
        walk_to_warp = {
            -w: (-2 * w - 2, -2 * w - 1, -2 * w, -2 * w + 1, -w - 1),
            w: (w + 1, 2 * w - 1, 2 * w, 2 * w + 1, 2 * w + 2),
            -1: (-w - 2, -2, w - 2, w - 1, 2 * w - 2),
            1: (-w + 1, -2 * w + 2, -w + 2, 2, w + 2),
        }

        dist = self.dist[:]
        dist[start] = 0
        queue = deque([start])
        while queue:
            x = queue.popleft()
            cur_dist = dist[x]
            if x == goal:
                break

            for walk, warp in walk_to_warp.items():
                nx = x + walk
                if dist[nx] > cur_dist:
                    dist[nx] = cur_dist
                    queue.appendleft(nx)
                    continue
                if dist[nx] >= 0:
                    continue

                for dx in warp:
                    nx = x + dx
                    if dist[nx] > cur_dist + 1:
                        dist[nx] = cur_dist + 1
                        queue.append(nx)

        return dist[goal] if dist[goal] != self.unsearched else -1


def main():
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline

    H, W = map(int, readline().split())
    *start, = map(int, readline().split())
    *goal, = map(int, readline().split())
    (*S,) = read().split()

    maze = WarpableMaze(H, W, S)
    print(maze.bfs(start, goal))


if __name__ == "__main__":
    main()


Measured memory_bytes: 96700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		int quo = a / b;
		int rem = a % b;
		String f = String.format("%.5f", ((double) a / (double) b));
		System.out.println(quo + " " + rem + " " + f);
	}

}

Measured memory_bytes: 26456
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    char A[3];
    scanf("2017/01/%s", A);
    printf("2018/01/%s\n", A);
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

int main (){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string s = "";
    int x = tx-sx;
    int y = ty-sy;
    for(int i=0;i<y;i++)
    s.insert(s.end(),'U');
    for(int i=0;i<x;i++)
    s.insert(s.end(),'R');

    for(int i=0;i<y;i++)
    s.insert(s.end(),'D');
    for(int i=0;i<x;i++)
    s.insert(s.end(),'L');
    

    s.insert(s.end(),'L');

    for(int i=0;i<y+1;i++)
    s.insert(s.end(),'U');
    for(int i=0;i<x+1;i++)
    s.insert(s.end(),'R');

    s.insert(s.end(),'D');

    s.insert(s.end(),'R');

    for(int i=0;i<y+1;i++)
    s.insert(s.end(),'D');
    for(int i=0;i<x+1;i++)
    s.insert(s.end(),'L');

    s.insert(s.end(),'U');

    cout << s;


}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define INF LLONG_MAX/2
#define PI acos(-1.0)
//#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    string t;
    cin>>t;
    REP(i,0,t.size()){
        if(t[i]!='?') cout<<t[i];
        else cout<<'D';
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3716
fun main(args: Array<String>) {
    val (k, s) = readLine()!!.split(" ").map(String::toInt)

    var result = 0
    for (x in 0..k) {
      for (y in 0..k) {
        val z = s - x - y
        if (0 <= z && z <= k) {
          result++
        }
      }
    }
    println(result)
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(ll i=ll(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	ll l,r;
	cin>>l>>r;

	ll ans=0;
	if(l/2019!=r/2019)ans=0;
	else{
		l%=2019;
		r%=2019;
		ans=INF;
		repi(i,l,r)repi(j,i+1,r+1)ans=min(ans,i*j%2019);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
# 2019-11-17 20:44:23(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    s, t = sys.stdin.read().split()

    count = 0
    for i in range(3):
        if s[i] == t[i]:
            count += 1
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define REP(i,n,a) for(int i=n;i>=a;i--)
const int maxN=5010;
int N,K;
long long A[maxN];
bool dp[maxN];
int main()
{
	cin>>N>>K;
	rep(i,0,N-1) cin>>A[i];
	sort(A,A+N);
	long long sum=0LL;
	rep(i,0,N-1) sum+=A[i];
	dp[0]=true;
	int ans=0;
	REP(i,N-1,0)
	{
		//cout<<sum<<" ##"<<endl;
		bool flag=false;
		rep(j,0,K-1) if(j+sum>=K&&dp[j])
		{
			flag=true;
			break;
		}
		sum-=A[i];
		if(!flag) ans++;
		REP(j,K-1,A[i]) dp[j]|=dp[j-A[i]];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 764
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

A, B = I()
if A == B:
    print("Draw")
elif A == 1:
    print("Alice")
elif B == 1:
    print("Bob")
else:
    if A > B:
        print("Alice")
    else:
        print("Bob")


Measured memory_bytes: 10428
#define S(x,y)s[(x)+(y)*(n+1)]
char s[101*100];
n,x,y,v,w,i,j,l,t;
main(f){
	scanf("%*d");
	for(;~scanf("%d",&n);){
		memset(s,' ',sizeof(s));
		for(y=0;y<n;y++){
			S(n,y)='\n';
			S(0,y)='#';
		}
		S(n,n-1)=0;
		x=0,y=0,v=1,w=0;
		l=n-1;
		for(l=n-1;l>0;l-=2){
			for(i=0;i<(l==1?1:2);i++){
				for(j=0;j<l;j++){
					x+=v,y+=w;
					S(x,y)='#';
				}
				t=v,v=-w,w=t;
			}
		}
		if(!f)
			puts("");
		f=0;
		puts(s);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int mp[50];
void s(int a,int b){swap(mp[a],mp[b]);}

void A(){
  s(1,24),s(4,27),s(7,30);
  s(16,18),s(10,21);
}

void B(){
  s(1,28),s(2,29),s(3,30);
  s(21,19),s(15,16);
}

void C(){
  s(3,22),s(6,25),s(9,28);
  s(12,19),s(13,15);
}

void D(){
  s(7,22),s(8,23),s(9,24);
  s(10,12),s(13,18);
}

bool check(){
  for(int i=1;i<=9;i++) if(mp[1]!=mp[i])return 0;
  int col;

  for(int i=10;i<=21;i++){
    if(i%3==1) col=mp[i];
    if(col!=mp[i])return 0;
  }
  for(int i=22;i<=30;i++) if(mp[22]!=mp[i])return 0;
  return 1;
}


int ans;
void saiki(int cnt){
  if(ans<=cnt)return;
  if(check())ans=cnt;

  A(),saiki(cnt+1),A();
  B(),saiki(cnt+1),B();
  C(),saiki(cnt+1),C();
  D(),saiki(cnt+1),D();
}

int main(){
  int n;
  cin>>n;
  while(n--){
    for(int i=1;i<=30;i++) cin>>mp[i];
    ans=8;
    saiki(0);
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<map>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
inline int read(){
    int w=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        w=(w<<3)+(w<<1)+ch-48;
        ch=getchar();
    }
    return w*f;
}
int n,m,cnt,head[500010],cur;
map<int,int> mapp[2000010];
struct Edge{
    int from,to,next,dis;
}edge[5000010];
inline void addedge(int u,int v,int w){
    cnt++;
    edge[cnt].from=u;
    edge[cnt].to=v;
    edge[cnt].dis=w;
    edge[cnt].next=head[u];
    head[u]=cnt;
}
inline void ins(int u,int v,int w){
    addedge(u,v,w);addedge(v,u,w);return;
}
inline int find(int x,int y){
    if(mapp[x][y]!=0)return mapp[x][y];
    else{
        mapp[x][y]=++cur;return cur;
    }
}
int dis[2000010];
struct Node{
    int u,dis;
    friend bool operator < (Node x,Node y){
        return x.dis > y.dis; 
    }
};
priority_queue<Node> q;
inline void dij(){
    memset(dis,0x3f,sizeof(dis));
    dis[1]=0;q.push((Node){1,dis[1]});
    while(!q.empty()){
        Node cur=q.top();q.pop();int u=cur.u;
        for(int i=head[u];i;i=edge[i].next){
            int v=edge[i].to;int w=edge[i].dis;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;q.push((Node){v,dis[v]});
            }
        }
    }
}
signed main(){
    n=read();m=read();cur=n;
    for(int i=1;i<=m;i++){
        int x=read();int y=read();int z=read();
        int id1=find(x,z);int id2=find(y,z);
        ins(x,id1,1);ins(y,id2,1);ins(id1,id2,0);
    }
    dij();
    if(dis[n]==INF)cout<<-1<<endl;
    else cout<<dis[n]/2<<endl;
    return 0;
}

Measured memory_bytes: 144508
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    pi data[30];
    rep(i,n)cin>>data[i].second>>data[i].first;
    sort(data,data+n);
    bool ok=true;
    int sum=0;
    rep(i,n){
      if(sum+data[i].second<=data[i].first)sum+=data[i].second;
      else ok=false;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

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

const int N = 200010;
int n, x, y, i, j, white, black, tot, cnt, last, k;
int a[N], nex[N], st[N], b[N], f[N], s[N], d[N], num[N];
bool g[N];

void add(int x, int y)
{
	b[++tot] = y;
	nex[tot] = st[x];
	st[x] = tot;
}

void build(int x, int deep)
{
	d[x] = deep;
	g[x] = 1;
	s[x] = 1;
	for (int i = st[x]; i; i = nex[i])
	{
		int y = b[i];
		if (!g[y])
		{
			build(y, deep + 1);
			f[y] = x;
			s[x] += s[y];
		}
	}
}

int main()
{
	scanf("%d", &n);
	for (i = 1; i < n; i++)
	{
		scanf("%d%d", &x, &y);
		add(x, y);
		add(y, x);
	}
	build(1, 1);
	//white = s[n];
	last = 0;
	k = n;
	while (k != 0)
	{
		a[++cnt] = k;
		num[cnt] = s[k] - s[last];
		last = k;
		k = f[k];
	}
	//black = s[1] - s[k];
	i = 1; j = cnt;
	while (i < j)
	{
		white += num[i];
		black += num[j];
		i++; j--;
	}
	if (i == j) black += num[i];
	puts((black <= white) ? "Snuke" : "Fennec");
	return 0;
}

Measured memory_bytes: 10240
n, m = map(int,input().split())
h = list(map(int,input().split()))
l = [1]*n
for i in range(m):
  a, b = map(int,input().split())
  if h[a-1] == h[b-1]:
    l[a-1] = 0
    l[b-1] = 0
  if h[a-1] > h[b-1]:
    l[b-1] = 0
  if h[a-1] < h[b-1]:
    l[a-1] = 0
print(l.count(1))

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


int main() {

  string a,b,c;
  cin >> a >> b >> c;

  int ax = a.size();
  int bx = b.size();
  int cx = c.size();
  
  string flag = "NO";
  
  if(a.at(ax-1) == b.at(0)){
    if(b.at(bx-1) == c.at(0)){
      flag = "YES";
    }
  }
  
  cout << flag;
}


Measured memory_bytes: 256
def gcd(x, y):
    if x == 0:
        return y

    return gcd(y % x, x)


def lcm(x, y):
    return x // gcd(x, y) * y


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

aa = [e // 2 for e in a]

for i, e in enumerate(aa):
    if i == 0:
        base = 0
        while e % 2 == 0:
            e //= 2
            base += 1

    else:
        cnt = 0
        while e % 2 == 0:
            e //= 2
            cnt += 1

        if cnt != base:
            print(0)
            exit()

c = 1
for e in aa:
    c = lcm(c, e)
    if c > m:
        print(0)
        exit()

ans = (m - c) // (2 * c) + 1
print(ans)


Measured memory_bytes: 14244
from sys import exit, stdin
S = list(stdin.readline().rstrip())
len_S = len(S)
if len_S % 2 != 0:
    S.pop(len_S//2)
    len_S -= 1
ans = 0
for i in range(len_S//2):
    if S[i] != S[abs(i-len_S)-1]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
H, W = list(map(int, input().split()))
ans = []

#目,円
for i in range(1, H):
    area1 = W*i
    area2 = (H-i)//2*W
    area3 = (H-(H-i)//2-i)*W
    area4 = (H-i)*(W//2)
    area5 = (H-i)*(W-(W//2))
    if area1 != 0 or area2 != 0 or area3 !=0:
        ans.append(max(area1, area2, area3)-min(area1, area2, area3))
    if area1 != 0 or area4 != 0 or area5 !=0:
        ans.append(max(area1, area4, area5)-min(area1, area4, area5))

#皿、ト
for i in range(1, W):
    area6 = H*i
    area7 = (W-i)//2*H
    area8 = (W-(W-i)//2-i)*H
    area9 = (W-i)*(H//2)
    area10 = (W-i)*(H-(H//2))
    if area6 != 0 or area7 != 0 or area8 !=0:
        ans.append(max(area6, area7, area8)-min(area6, area7, area8))
    if area6 != 0 or area9 != 0 or area10 !=0:
        ans.append(max(area6, area9, area10)-min(area6, area9, area10))

print(min(ans))

Measured memory_bytes: 18928
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    S = input().rstrip()
    ans = 0
    for i in range(len(S) // 2):
        if S[i] != S[-i - 1]:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
n, m = map(int, input().split())
d = 10 ** 9 + 7


def factorial(n):
    ans = 1
    for q in range(1, n + 1):
        ans *= q
        if ans >= d:
            ans %= d
    return ans


if abs(n - m) > 1:
    print(0)
    exit(0)

if n == m:
    ans = ((factorial(n) % d) ** 2) * 2 % d
if n != m:
    ans = factorial(n) * factorial(m) % d
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

// ??????g????????????????????\?????????
void insertionSort(int A[], int n, int g){
	for(int i = g; i < n; i++){
		int v = A[i];
		int j = i - g;
		while(j >= 0 && A[j] > v){
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n){
	// ??°???G = {1, 4, 13, 40, 121, 364, 1093, ???} ?????????
	for (int h = 1; ; ){
		if(h > n) break;
		G.push_back(h);
		h = 3*h + 1;
	}

	for(int i=G.size()-1; i >= 0; i--){ // ?????????G[i] = g ?????????
		insertionSort(A, n, G[i]);
	}
}

int main(){
	cin >> n;
	// ??????????????\???scanf??¢??°????????¨
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	cnt = 0;

	shellSort(A,n);

	cout << G.size() << endl;
	for(int i=G.size()-1;i>=0;i--){
		printf("%d",G[i]);
		if(i)printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++) printf("%d\n",A[i]);

	return 0;
}

Measured memory_bytes: 7108
n, m, q = map(int, input().split())
memo  = [[0 for i in range(n+1)] for j in range(n+1)]
ans = [[0 for i in range(n+1)]for j in range(n+1)]
for i in range(m):
    l, r = map(int, input().split())
    memo[l][r] += 1
for i in range(1, n+1):
    for j in range(1, n+1):
        memo[i][j] += memo[i][j - 1]
for i in range(1, n+1):
    for j in range(1, n+1):
        memo[i][j] += memo[i - 1][j]
for i in range(q):
    l, r = map(int, input().split())
    print(memo[r][r] + memo[l-1][l-1] - memo[r][l - 1] - memo[l - 1][r])

Measured memory_bytes: 61272
#include<iostream>
#include<vector>
#include<algorithm>
#include<list>
#include<set>
using namespace std;

int n;

vector<int> fenech(1000001);
vector<int> sunuke(1000001);
set<int> se;

void dfs(int c,int depth,vector<vector<int> >& tree,bool f){

	if(f){
		fenech[c] = depth;
	}else{
		sunuke[c] = depth;
	}

	for(int i=0;i<tree[c].size();++i){
		int next = tree[c][i];
		if(se.find(next) != se.end()) continue;
		se.insert(next);
		dfs(next,depth+1,tree,f);
	}
}


int main(){
	cin >> n;
	vector<vector<int> > tree(n+1);

	int a,b;
	for(int i=1;i<n;++i){
		cin >> a >> b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	se.insert(1);
	dfs(1,0,tree,true);
	se.clear();
	se.insert(n);
	dfs(n,0,tree,false);

	int nfenech = 0;
	int nsunuke = 0;

	for(int i=1;i<=n;++i){
		if(fenech[i] <= sunuke[i]){
			nfenech++;
		}else{
			nsunuke++;
		}
	}

	if(nfenech > nsunuke) cout << "Fennec" <<endl;
	else cout << "Snuke" <<endl;
	
	return 0;
}




Measured memory_bytes: 24448
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long double ld;
typedef long long int lli;
typedef pair <lli, lli> pii;
#define pb push_back
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const lli N = 1e3 + 10, N2 = 2e5, delta = 46639, mod = 1e9 + 7, oo = 1e18, LOG = 20, SQ = 300;
const ld PI = 3.141592653589793;

lli dp[N][N];

int32_t main() {
	fast;
	lli h, w;
	cin >> h >> w;
	dp[1][1] = 1;
	for (lli i = 1; i <= h; i++)
		for (lli j = 1; j <= w; j++) {
			char c;
			cin >> c;
			if (c == '.' && (i > 1 || j > 1))
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
		}
	cout << dp[h][w] << '\n';
	return 0;
}


Measured memory_bytes: 8192
#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define precise(a)          cout<<fixed<<setprecision(a)
#define nl                  std::cout<<'\n'
#define INF                 LLONG_MAX
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T> 
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U> 
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T> 
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U> 
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T> 
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(ll &T)
{
    string s;
    std::cin>>s;

    if(s[2]==s[3] and s[4]==s[5])
        std::cout<<"Yes\n";
    else
        std::cout<<"No\n";
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif
    
    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAXN 100005

char S[MAXN], T[MAXN];
int A[MAXN], B[MAXN], C[MAXN], D[MAXN];
int SA[MAXN], TA[MAXN];

int main() {
	int N, M, Q;

	scanf("%s%s%d", S + 1, T + 1, &Q);
	for(int i = 0; i < Q; i++) scanf("%d%d%d%d", A + i, B + i, C + i, D + i);

	for(N = 1; S[N]; N++) SA[N] = (S[N] == 'A' ? 1 : 0) + SA[N - 1];
	for(M = 1; T[M]; M++) TA[M] = (T[M] == 'A' ? 1 : 0) + TA[M - 1];

	for(int i = 0; i < Q; i++) {
		if((2 * (SA[B[i]] - SA[A[i] - 1] - TA[D[i]] + TA[C[i] - 1]) - B[i] + A[i] + D[i] - C[i]) % 3 == 0)
			printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    struct edge{
        int to, idx;
    };
    vector<vector<edge>> g(n);
    for (int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(edge{b, i});
        g[b].push_back(edge{a, i});
    }
    
    int c = 0;
    int r;
    for (int i = 0; i < n; i++) {
        if (g[i].size()>c){
            c = g[i].size();
            r = i;
        }
    }
    
    cout << c << endl;
    
    vector<int> ans(n-1);
    vector<bool> visited(n, false);
    function<void(int, int, int)> dfs = [&](int v, int p, int pc) {
        if (visited[v]) return;
        visited[v] = true;
        int cc = 0;
        for (auto &e: g[v]) {
            if (e.to == p) continue;
            if (cc == pc) cc++;
            ans[e.idx] = cc;
            dfs(e.to, v, cc);
            cc++;
        }
    };
    
    dfs(r, -1, -1);
    
    for (auto e: ans) cout << e+1 << '\n';

    
    
    return 0;
}


Measured memory_bytes: 9216
def solve():
  L, R = map(int, input().split())
  ans = 2019
  for i in range(L, R):
    for j in range(i + 1, R + 1):
      v = i * j % 2019
      if v < ans: ans = v
      if ans == 0: return 0
  return ans

print(solve())


Measured memory_bytes: 2940
#include <iostream>
#include <list> //???????????????????????????
#include <vector>//????????¢??????????????????
#include <climits>
#include <cmath>
using namespace std;

struct Ten{
	double X;
	double Y;

};

void out(Ten t){
	
	cout << t.X << " "<<t.Y <<endl;
	
}

void solve(Ten P1, Ten P2 ,int n){
	if(n ==0){
		return;
	}
	Ten s;
	Ten u;
	Ten t;
	Ten v;
	
	v.X=(P2.X-P1.X)/3;
	v.Y=(P2.Y-P1.Y)/3;
	s.X =P1.X+v.X;
	s.Y =P1.Y+v.Y;
	u.X=s.X+(v.X*cos(60*M_PI/180)-v.Y*sin(60*M_PI/180));
	u.Y=s.Y+(v.X*sin(60*M_PI/180)+v.Y*cos(60*M_PI/180));
	t.X =P2.X-v.X;
	t.Y =P2.Y-v.Y;

	/*Ten itr_t = list1.insert(P2, t);
	Ten itr_u = list1.insert(itr_t, u);
	Ten itr_s = list1.insert(itr_u,s);*/

	
	if(n == 1){
		//out(P1);
		//out(s);
		//out(u);
		//out(t);
		//out(P2);
		
	}
	n--;
	
	solve(P1, s , n);
	if(n==0){
		out(s);
	}
	solve(s, u, n);
	if(n==0){
		out(u);
	}
	solve(u, t, n);
	if(n==0){
		out(t);
	}
	solve(t, P2, n);
	
	if(n ==0){
		out(P2);
	}
}



int main(void){
	int n;
	
	cin >> n;
	
	
	//list <Ten> list1;

	Ten siten;
	siten.X =0;
	siten.Y =0;
	Ten syuten;
	syuten.X =100;
	syuten.Y =0;
	
	/*list1.push_back(siten);
	list1.push_back(syuten);*/
	out(siten);
	solve(siten, syuten, n);
	//out(syuten);
	
	
	/*for(Ten i=list1.begin() ; i != list1.end(); i++){
		
		cout << (*i).X << " "<< (*i).Y  <<endl;
		
		
	}*/
	if(n ==0){
		out(syuten);
	}
return 0;
	
}

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

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

  vector<int> ASCII(26,0);
  for(int i=0;i<4;i++){
    ASCII.at(S.at(i)-'A') += 1;
  }

  bool flag=true;
  for(int i=0;i<26;i++){
    if(ASCII.at(i)!=2 && ASCII.at(i)!=0){
      flag = false;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


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

int main(){
  static const double pi = 3.141592653589793;
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double argh, argm, arg;
  argh = h * 30.0 + 0.5 * m;
  argm = 6.0 * m;
  arg = min(abs(argh - argm), abs(360.0 - argh + argm));
  double ans = sqrt(a * a + b * b - 2 * a * b * cos(pi / 180 * arg));
  printf("%.9f\n", ans);
  return 0;
}

Measured memory_bytes: 4164
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    double N;
    while(cin>>N){
        double A=0;
        A=N;
        for(int i=2;i<11;i++){
            if(i%2==0)N*=2;
            else N/=3;
            A+=N;
        }
        printf("%.8lf\n",A);
    }
    return 0;
}

Measured memory_bytes: 1236
N=input()
if N[-1] == "2" :
    print("hon")
elif N[-1] == "4" :
    print("hon")
elif N[-1] == "5" :
    print("hon")
elif N[-1] == "7" :
    print("hon")
elif N[-1] == "9" :
    print("hon")
elif N[-1] == "1" :
    print("pon")
elif N[-1] == "6" :
    print("pon")
elif N[-1] == "8" :
    print("pon")
elif N[-1] == "0" :
    print("pon")
else:
    print("bon")


Measured memory_bytes: 9132
#include <iostream>

using namespace std;

int main(){
  int H,W;
  while(1){
    cin >> H >> W;
    if(H==0 && W == 0) break;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	if(i == 0 || j == 0 || j == W-1 || i == H-1) cout << '#';
	else cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



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

#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)

#define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)

#define getI(a) scanf("%d", &a) //next three are handy ways to get ints, it's also force you to use '&' sign
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)

#define wez(n) int (n); scanf("%d",&(n)) //handy if the input is right after the definition of a variable
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))

#define whileZ int T; getI(T); while(T--)
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))

#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) // traverse an STL data structure

#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"

#define PRESENT(c,x) ((c).find(x) != (c).end())

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short

//for map, pair
#define mp make_pair
#define fi first
#define se second

// for debug
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)

//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

int main()
{
    wez3(w,h,n);
    int a = max(w,h);
    int b = min(w,h);

    F(i,1,b+1) {
        if ((a*i)>=n) {cout << i; return 0;}
    }
}

Measured memory_bytes: 256
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    string a,b; cin >> a >> b;
    if(a.size()<b.size()) cout << "LESS"<<endl;
    else if(a.size()>b.size()) cout << "GREATER" << endl;
    else{
        rep(i,a.size()){
            if(a[i]-'0'>b[i]-'0'){
                cout <<"GREATER"<<endl;
                return 0;
            }else if(a[i]-'0'<b[i]-'0'){
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
}


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


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

    bool f = false;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if(i*j == n) {
                f = true;
            }
        }
    }

    std::string ans = f ? "Yes" : "No";

    std::cout << ans << "\n";
}

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

typedef long long int ll;

int main()
{
	ios::sync_with_stdio(0);
	ll n;
	cin >> n;
	ll a[n][3];
	ll dp[n][3];
	ll i,j;
	for(i=0;i<n;i++)
		cin >> a[i][0] >>  a[i][1] >>  a[i][2] ;
	dp[n-1][0]=a[n-1][0];
	dp[n-1][1]=a[n-1][1];
	dp[n-1][2]=a[n-1][2];
	for(i=n-2;i>=0;i--)
	{
		dp[i][0] = a[i][0] + max(dp[i+1][1],dp[i+1][2]);
		dp[i][1] = a[i][1] + max(dp[i+1][0],dp[i+1][2]);
		dp[i][2] = a[i][2] + max(dp[i+1][1],dp[i+1][0]);
	}
	ll ans = max(dp[0][0],dp[0][1]);
	ans = max(ans,dp[0][2]);
	cout << ans << "\n";
	return 0;
}	

Measured memory_bytes: 4992
#include <stdio.h>
int main(){
int n,top,low,temp;
long long int tot;
scanf("%d%d",&n,&low);
tot=top=low;
for(int i=1;i<n;i++){
scanf("%d",&temp);
if(temp>top)top=temp;
if(temp<low)low=temp;
tot+=temp;
}
printf("%d %d %lld\n",low,top,tot);
}


Measured memory_bytes: 2712
//#include "pch.h"
#include <iostream>
#include<string>
#include<algorithm>

#include<iostream>
using namespace std;

int main() {
	int N, X;
	int L[110],D[110];
	cin >> N >> X;
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	D[0] = 0;
	for (int i = 1; i < N+1; i++) {
		D[i]=D[i-1]+L[i-1];
	}
	int counter = 0;
	for (int i = 0; i < N+1; i++) {
		if (D[i] > X) break;
		counter++;
	}
	cout << counter << endl;
	
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int S = sc.nextInt();
        int total = 0;
        for(int i = 0;i <= K;i++){
            for(int j = 0;j <= K;j++){
                    int last = S - i - j;
                    if(last >= 0 && last <= K) total++;
            }
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 23764
#include <stdio.h>
int main(void) {
	int i, j, n;
	int id=0;
	char no[2][4] = {"No", "Yes"};
	scanf("%d", &n);

	for (i=1; i<=9; i++) {
		for (j=i; j<=9; j++) {
			if (n == i*j) {
				id = 1;
			}
		}
	}
	
	printf("%s", no[id]);
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
N,L=map(int,input().split())
A=[]
for i in range(N):
    A.append(L+i)
if max(A)<0:
    print(sum(A)-max(A))
elif min(A)>0:
    print(sum(A)-min(A))
else:
    print(sum(A))        

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

int main() {
    int a,b,c;
    cin>>a>>b>>c;

    if(a-b>=c){
        cout<<0<<endl;
    }

    else {
        cout<<c-(a-b)<<endl;

    }


}


Measured memory_bytes: 256
N,K=map(int,input().split())

answer=0
if K==0:
  answer=N**2
else:
  for i in range(K+1,N+1):
    #print(i,(i-K)*((N+1)//i))
    #print(i,max(0,(N+1)%i-K))
    answer+=(i-K)*((N+1)//i)+max(0,(N+1)%i-K)
    
print(answer)

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

int main(){
    
    int n, k;
    cin >> n >> k;
    vector<int>a(n);
    int cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] >= k)cnt++;
    }
    
    cout << cnt << endl;
    
}


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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int planA = N*A;
    int planB = B;

    if(planA < planB){
    	cout << planA << endl;
    }
    else if(planA > planB){
    	cout << planB << endl;
    }
    else{
        cout << planA << endl;
    }
  
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        PriorityQueue<Long> A = new PriorityQueue<>(Collections.reverseOrder());
        for (int i=0; i<N; i++) {
            A.add(Long.parseLong(sc.next()));
        }
        sc.close();

        for (int i=0; i<M; i++) {
            long new_price = (long)A.poll()/2;
            A.add(new_price);
        }

        long sum = 0;
        for (long a : A) {
            sum += a;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 50024
def main():
    n, a = list(map(int, input().split()))
    X = list(map(lambda x: int(x) - a, input().split()))
    b = max(max([x for x in X]) + a, a)
    dp = [[0] * (2 * b * n + 1) for  _ in range(n + 1)]
    dp[0][b * n] = 1
    for i in range(1, n + 1):
        for j in range(2 * b * n + 1):
            if 0 <= j - X[i - 1] < 2 * b * n:
                dp[i][j] = dp[i - 1][j] + dp[i - 1][j - X[i - 1]]
            else:
                dp[i][j] = dp[i - 1][j]
    print(dp[n][b * n] - 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 11580
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>

typedef long long i64;

using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<i64> ppp(N);
    vector<i64> ppm(N);
    vector<i64> pmp(N);
    vector<i64> pmm(N);
    vector<i64> mpp(N);
    vector<i64> mpm(N);
    vector<i64> mmp(N);

    for(int i=0;i<N;i++){
        i64 a,b,c;
        cin>>a>>b>>c;
        ppp[i] = a+b+c;
        ppm[i] = a+b-c;
        pmp[i] = a-b+c;
        pmm[i] = a-b-c;
        mpp[i] = -a+b+c;
        mpm[i] = -a+b-c;
        mmp[i] = -a-b+c;
    }
    
    i64 ans = 0;

    sort(ppp.rbegin(),ppp.rend());
    sort(ppm.rbegin(),ppm.rend());
    sort(pmp.rbegin(),pmp.rend());
    sort(pmm.rbegin(),pmm.rend());
    sort(mpp.rbegin(),mpp.rend());
    sort(mpm.rbegin(),mpm.rend());
    sort(mmp.rbegin(),mmp.rend());
    
    vector<i64> sum(7);

    for(int i=0;i<M;i++){
        sum[0] += ppp[i]; 
        sum[1] += ppm[i];
        sum[2] += pmp[i];
        sum[3] += pmm[i];
        sum[4] += mpp[i];
        sum[5] += mpm[i];
        sum[6] += mmp[i];
        
    }

    for(int i=0;i<7;i++){
        ans = max(ans,abs(sum[i]));   
    }


    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#define NMAX 200000

using namespace std;

int main() {
  int n,P[NMAX],ans=0,min=200002;
  cin>>n;
  for(int i=0;i<n;i++){
    scanf("%d",&P[i]);
    if(P[i]<=min){
      min=P[i];
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(3 * n);
    rep(i, 0, 3 * n){
        cin >> a[i];
    }
    vector<int> pre(3 * n), aft(3 * n);
    priority_queue<int, vector<int>, greater<int> > pq;
    int sum = 0;
    rep(i, 0, n){
        sum += a[i];
        pq.push(a[i]);
    }
    pre[n - 1] = sum;
    rep(i, n, 2 * n){
        pq.push(a[i]);
        int tmp = pq.top(); pq.pop();
        sum = sum + a[i] - tmp;
        pre[i] = sum;
    }
    sum = 0;
    priority_queue<int> pq2;
    rep(i, 2 * n, 3 * n){
        sum += a[i];
        pq2.push(a[i]);
    }
    aft[2 * n] = sum;
    for(int i = 2 * n - 1; i >= n; i--){
        pq2.push(a[i]);
        int tmp = pq2.top(); pq2.pop();
        sum = sum + a[i] - tmp;
        aft[i] = sum;
    }
    int ans = -INF;
    for(int i = n - 1; i < 2 * n; i++){
        int tmp = pre[i] - aft[i + 1];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int dp[2][101][10001];
int a[101],b[101],c[101];
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n,C,ai,bi;
    cin>>n>>C;
    rep(i,n){
        cin>>a[i]>>b[i]>>c[i];
    }
    memset(dp,-1,sizeof(dp));
    dp[0][0][0]=0;
    rep(i,n){
        rep(j,C+1)rep(k,i*100+1){
            if(dp[0][j][k]==-1) continue;
            int t=dp[0][j][k];
            if(j+c[i]<=C){
                int u=max(k+a[i],t+b[i]);
                int l=min(k+a[i],t+b[i]);
                dp[1][j+c[i]][u]=max(dp[1][j+c[i]][u],l);
                u=max(k+b[i],t+a[i]);
                l=min(k+b[i],t+a[i]);
                dp[1][j+c[i]][u]=max(dp[1][j+c[i]][u],l);            
            }
            dp[1][j][k]=max(dp[1][j][k],t);
        }
        swap(dp[0],dp[1]);
        memset(dp[1],-1,sizeof(dp[1]));
    }
    int mx=0;
    rep(i,C+1)rep(j,10001)if(dp[0][i][j]!=-1) mx=max(mx,dp[0][i][j]);
    cout<<mx<<endl;
    return 0;
}


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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

vector<char> boin = {'a','i','u','e','o'};
vector<char> alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main(){
    int X;
    cin >> X;
    if(X >= 2100){
        cout << 1 << endl;
    }else{
        int Y = X/100;
        if((X-Y*100) <= Y*5)cout << 1 << endl;
        else cout << 0 << endl;
    }
    //cin >> X;
}

Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n getLine
      let ls' = map (map read . words) ls
          ansL = map rank ls'
      mapM_ putStrLn ansL
      main

rank :: [Int] -> String
rank [m,e,j]
  | (elem 100 [m,e,j]) || 90 <= aveME || 80 <= aveAll = "A"
  | 70 <= aveAll || (50 <= aveAll && (80 <= m || 80 <= e)) = "B"
  | otherwise = "C"
  where
    aveAll = (m+e+j) `div` 3
    aveME = (m+e) `div` 2

Measured memory_bytes: 4052
import itertools
a=list(input())
ans="Yes"
for i,j in enumerate(a):
  if i%2==0:
    if not(j=="R" or j=="U" or j=="D"):
      ans="No"
  else:
    if not (j=="L" or j=="U" or j=="D"):
      ans="No"
print(ans)

Measured memory_bytes: 3060
ans = float("inf")
N,M,X = map(int,input().split())
C = []
A = []
for i in range(N):
    c,*a = map(int,input().split())
    C.append(c)
    A.append(a)
for i in range(pow(2,N)):
    n = i
    L = []
    for j in range(N):
        L.append(n%2)
        n//=2
    cost = 0
    S = [0]*M
    for j in range(N):
        if L[j]:
            cost+=C[j]
            for k in range(M):
                S[k]+=A[j][k]
    if min(S)>=X:
        ans = min(ans,cost)
if ans==float("inf"):
    ans = -1
print(ans)

Measured memory_bytes: 9244
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

const int N = 1e3+7;
int n,x[N][N],d;

int32_t main()
{
	fast;

	cin>>n>>d;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=d;j++)
			cin>>x[i][j];
	int cnt = 0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int sum = 0;
			for(int k=1;k<=d;k++)
				sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			double k1 = sqrt(sum);
			int k2 = (int)k1;
			if(k1==k2)
				cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
        
    if(a>n){
      System.out.println(n);
      return;
    }
    
    long o = n/(a+b);
    o = o*a;
    long nokori = n % (a+b);

    
    if(nokori >=a)
      o += a;
    else
      o += nokori;
      
    System.out.println(o);
  }
}

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

import sys
import os


def print_matrix(M):
    print('matrix')
    for i, row in enumerate(M):
        print(i, end=': ')
        print(row)

N, E = list(map(int, input().split()))
# Node
# Edge

# 隣接するノードをリスト管理
M = [[] for j in range(N)]
#print(M)


# データを隣接行列に入れていく
for _ in range(E):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

    # a -> b
    M[a].append(b)
    # b -> a
    M[b].append(a)
#print_matrix(M)

# 訪問管理
visited = [False] * N

def get_path(start_index):
    answer = []
    # そこからはじめる
    answer.append(start_index)
    visited[start_index] = True
    current_index = start_index

    # 次にどこに行けるか
    while True:
        candidates = M[current_index]
        #print('current index', current_index)
        #print('candidates', candidates)

        next_index = None
        # その中のどれにいこうか、訪れてないもの
        for candidate_i in candidates:
            if not visited[candidate_i]:
                #print('君に決めた！', candidate_i)
                next_index = candidate_i
                visited[candidate_i] = True
                break
        if next_index is not None:
            answer.append(next_index)
            visited[next_index] = True
            current_index = next_index
        else:
            #print('行けるだけ行った 最後は', current_index)
            break
    return answer

def check_condition(path):
    left_index = path[0]
    destinations = M[left_index]
    for dest in destinations:
        if not visited[dest]:
            return False, dest

    right_index = path[-1]
    destinations = M[right_index]
    for dest in destinations:
        if not visited[dest]:
            return False, dest
    return True, None


full_path = []
next_index = 0
while True:
    path = get_path(next_index)

    if full_path:
        path.reverse()
        full_path = path + full_path
    else:
        full_path = path

    check_result = check_condition(full_path)
    if check_result[0]:
        # check ok
        break
    else:
        #print('もういっちょ', full_path, check_result[1])
        next_index = check_result[1]


#print(full_path)
print(len(full_path))
answer2 = []
for v in full_path:
    # indexあわせ
    answer2.append(str(v+1))
print(' '.join(answer2))

Measured memory_bytes: 31392
s=sorted(set(input()))

a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

if s==a:
    print('None')
for i in a:
    if i not in s:
        print(i)
        break

Measured memory_bytes: 3188