akhauriyash/Code-Regression huggingface dataset:
//                                               KEEP GRINDING
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>   new_data_set;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define int long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define precise(i) fixed << setprecision(10) << i
#define f(i,a,b) for(int i=a;i<b;++i)

#define endl '\n'
#define debug cout<<"\n========================================\n"<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;

#define all(a) a.begin(),a.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define mx(a) *max_element(a)
#define mn(a) *min_element(a) 
#define LB lower_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >= OUR VALUE 
#define UB upper_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS > OUR VALUE 

#define fr first
#define sc second

#define MAXN 500000
#define INF 9223372036854775807
signed main(){
    fastio
    int x,y;
    cin>>x>>y;
    for(int i=0;i<=x;i++){
    	if(2*i +4*(x-i)==y){
    		cout<<"Yes";
    		return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 














int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    ll res=1LL<<60;
    for(int i=1;i<=100;i++)
    {
         int t=i;
         ll tmp=0;
         for(int i=0;i<n;i++)
         {
              tmp+=(a[i]-t)*(a[i]-t);
         }
         res=min(res,tmp);
    }
    cout<<res;
}
























 
 
 
 
 

















Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <limits.h>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
const int maxn = 1e4 + 7;
int main(void)
{
    int n;
    cin >> n;
    if(!n) cout << 1;
    else cout << 0;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    map<string, int> m;
    rep(i, N){
        string s;
        cin >> s;
        if(m.count(s)) m.at(s)++;
        else m[s] = 1; 
    }

    int max_value = 0;
    for(auto p : m){
        auto value = p.second;
        if(max_value < value){
            max_value = value;
        }
    }
    for(auto p : m){
        auto key = p.first;
        auto value = p.second;
        if(value == max_value){
            cout << key << endl;
        }
    }
    
    
}


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

int Q;
char S[101010], T[101010];
int SA[101010], TA[101010];

int main(){
    int s, e, l, r;
    scanf("%s", S+1);
    scanf("%s", T+1);
    for (int i=1; S[i]; i++){
        if (S[i] == 'A') SA[i]++;
        SA[i] += SA[i-1];
    }
    for (int i=1; T[i]; i++){
        if (T[i] == 'A') TA[i]++;
        TA[i] += TA[i-1];
    }
    scanf("%d", &Q);
    while (Q--){
        scanf("%d %d %d %d", &s, &e, &l, &r);
        int x = (2*(SA[e] - SA[s-1]) - (e-s+1) + 3000000)%3;
        int y = (2*(TA[r] - TA[l-1]) - (r-l+1) + 3000000)%3;
        puts((x == y) ? "YES" : "NO");
    }
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define pb push_back
#define mp make_pair
#define fi(i,start,end) for(int i=start; i < end ; ++i)
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
//#define mod 1000000007



using namespace std;




int main()
{
	long long unsigned int n;
	cin>>n;
	if(n==2){cout<< 1;return 0;}
	long long unsigned int ans=0;
	for(long long unsigned int a=1;a<sqrt(n-1);a++)
    {
        for(long long unsigned int b=a;a*b < n;b++)
        {
            ans++;
        }
    }
    ans=ans*2;


    ans=ans - int( sqrt(n-1));
    cout<<ans;

}



Measured memory_bytes: 3636
N, K = map(int, input().split())
count = 0
mod = 10**9+7
for i in range(K, N+2):
    max_num = (i * (N + N - i + 1)) // 2
    min_num = (i * (i - 1)) // 2
    count += (max_num - min_num + 1)
    count %= mod

print(count)


Measured memory_bytes: 9168
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = ListBuffer.empty[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map(l(1))
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Boolean](721)
    log.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = true)
    })
    time.count(_ == true)
  }

  def solve(s:String):Unit = {
    val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 57364
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
L,R = Line(N,2)

l = max(L)
li = L.index(l)
r = min(R)
ri = R.index(r)
ans = max(r-l+1,0) + max([0 if (i==li or i==ri) else R[i]-L[i]+1 for i in range(N)])
if li==ri:
    print(ans)
    exit()

x = []
for i in range(N):
    if i==li or i==ri:
        continue
    else:
        x1 = max(R[i]-l+1, 0)
        x2 = max(r-L[i]+1, 0)
        x.append((x1,x2))

x.sort(key=lambda s:(-s[0],s[1]))

amin = R[li]-l+1
bmin = r-L[ri]+1
one = [amin]
two = [bmin]

for x0 in x:
    amin = min(amin,x0[0])
    one.append(amin)
for x0 in x[::-1]:
    bmin = min(bmin,x0[1])
    two.append(bmin)

two = list(reversed(two))
for i in range(len(one)):
    temp = one[i]+two[i]
    if temp>ans:
        ans = temp

print(ans)

Measured memory_bytes: 82396
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int n, c;
	cin >> n >> c;
	cout << n*n - c << endl;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

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

	vector<int> cnt(4);
	string s;
	FOR(i, 1, n) {
		cin >> s;
		if (s == "AC") {
			cnt[0]++;
		}
		else if (s == "WA") {
			cnt[1]++;
		}
		else if (s == "TLE") {
			cnt[2]++;
		}
		else {
			cnt[3]++;
		}
	}
	cout << "AC x " << cnt[0] << endl;
	cout << "WA x " << cnt[1] << endl;
	cout << "TLE x " << cnt[2] << endl;
	cout << "RE x " << cnt[3] << endl;
}

Measured memory_bytes: 3632
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
# define M_PI 3.141592
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

int main()
{
	int n, m;
	cin >> n >> m; cin.ignore();
	int a[21][21];
	memset(a, -1, sizeof a);
	for (int i = 0; i < m; i++)
	{
		int x, y, z, w;
		scanf("%d,%d,%d,%d", &x, &y, &z, &w);
		a[x][y] = z;
		a[y][x] = w;
	}
	int s, g, p, v;
	scanf("%d,%d,%d,%d", &s, &g, &p, &v);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			for (int k = 1; k <= n; k++)
			{
				if (a[i][k] == -1 || a[k][j] == -1)continue;
				if (a[i][j] == -1)a[i][j] = a[i][k] + a[k][j];
				else a[i][j] = min(a[i][k] + a[k][j], a[i][j]);
			}
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			for (int k = 1; k <= n; k++)
			{
				if (a[i][k] == -1 || a[k][j] == -1)continue;
				if (a[i][j] == -1)a[i][j] = a[i][k] + a[k][j];
				else a[i][j] = min(a[i][k] + a[k][j], a[i][j]);
			}
		}
	}
	cout << p - v - a[s][g] - a[g][s] << endl;
}

Measured memory_bytes: 1240
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// posList to record the position for the left side of every valley
		LinkedList<Integer> posList = new LinkedList<Integer>();
		// areaList to record the area for every valley
		LinkedList<Record> areaList = new LinkedList<Record>();
		
		// sum to record whole area, area to record the area for every valley
		int sum = 0, area=0;
		
		Scanner sc = new Scanner(System.in);
		String[] input = sc.nextLine().split("");
		sc.close();
		for (int i=0; i<input.length; i++) {
			if ("\\".equals(input[i])) {
				posList.add(i);
			} else if ("/".equals(input[i]) && (!posList.isEmpty())) {
				Integer leftPos = posList.removeLast();
				sum += i - leftPos;
				area = i - leftPos;
				
				// while to sum up all the area for the deep valley that includes small valleys
				// like "\\/\//", there are two floors to assemble the whole area
				// areaList push the area of first "\/", then push the second "\/", then include the area of the second floor "\   /"
				while (!areaList.isEmpty() && areaList.getLast().getPos()>leftPos) {
					area += areaList.removeLast().getArea();
				}
				areaList.add(new Record(leftPos, area));
			}
		}
		
		System.out.println(sum);
		System.out.print(areaList.size());
		while (!areaList.isEmpty()) {
			System.out.print(" " + areaList.removeFirst().getArea());
		}
		System.out.println();
		
	}
	
	

}

class Record {
	private int pos;
	private int area;
	public int getPos() {
		return pos;
	}
	public void setPos(int pos) {
		this.pos = pos;
	}
	public int getArea() {
		return area;
	}
	public void setArea(int area) {
		this.area = area;
	}
	public Record(int pos, int area) {
		super();
		this.pos = pos;
		this.area = area;
	}
	
}


Measured memory_bytes: 31840
//coded by: pranonrahman-------------------------------------
//-----------------------------------------------------------
//-----------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define O_O ios_base::sync_with_stdio(0); cin.tie(NULL)
#define endl '\n'
#define PI acos(-1.0)
#define CASE(n) cout << "Case " << n << ": "
#define CASE_(n) cout << "Case " << n << endl
#define FIXED(n) cout << fixed << setprecision(n)
#define testPrint(n) cout << "test" << n << endl;


int main()
{
    O_O;
    long long t=1;
    //cin >> t;
    long long T = t;
    while(t--)
    {
        //write your code here
        char ch;
        cin >> ch;
        if(ch>='a')  cout << 'a';
        else        cout << 'A';
    }
    return 0;
}





Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int main(){
  int a,b,c,k,i,j,sum=0;
  cin>>a>>b>>c>>k;
  while(a){
    if(k==0){
      break;
    }
    sum++;
    a--;
    k--;
    
  }
  while(b){
    if(k==0){
      break;
    }
    b--;
    k--;
  }
  while(c){
    if(k==0){
      break;
    }
    c--;
    sum--;
    k--;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3540
#include <complex>
#include <vector>
#include <cmath>
#include <utility>
#include <cassert>
#include <cmath>
#include <iostream>

const double EPS=1e-10;

#define equals(a, b) (fabs((a)-(b))<EPS)
#define X real()
#define Y imag()

using namespace std;

typedef complex<double> Point;
typedef complex<double> Vector;

struct Segment {
    Point p1, p2;
};
typedef Segment Line;

struct Circle {
    Point c;
    double r;
    Circle(Point c=Point(), double r=0.0) :
        c(c),r(r){}
};

typedef vector<Point> Polygon;

double dot(Vector a, Vector b) {
    return a.X*b.X + a.Y*b.Y;
}

double cross(Vector a,Vector b) {
    return a.X*b.Y - a.Y*b.X;
}

Point project(Segment s, Point p) {
    Vector base = s.p2-s.p1;
    double r=dot(p-s.p1,base) / norm(base);
    return s.p1+base*r;
}

Point reflect(Segment s, Point p) {
    return p+(project(s,p)-p)*2.0;
}

enum CCW {
    COUNTER_CLOCKWISE=1,
    CLOCKWISE=-1,
    ONLINE_BACK=2,
    ONLINE_FRONT=-2,
    ON_SEGMENT=0,
};

int ccw(Point p0, Point p1, Point p2) {
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS) return CCW::COUNTER_CLOCKWISE;
    if(cross(a,b)<-EPS) return CCW::CLOCKWISE;
    if(dot(a,b)<-EPS) return CCW::ONLINE_BACK;
    if(norm(a)<norm(b)) return CCW::ONLINE_FRONT;

    return CCW::ON_SEGMENT;
}

double getDistance(Point a,Point b) {
    return abs(a-b);
}

double getDistanceLP(Line l, Point p) {
    return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

bool intersect(Point p1,Point p2,Point p3,Point p4) {
    return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
            ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2) {
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}
bool intersect(Circle c,Line l) {
    return getDistanceLP(l,c.r)<=c.r;
}

Point getCrossPoint(Segment s1,Segment s2) {
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}
pair<Point, Point> getCrossPoints(Circle c, Line l) {
    // assert(intersect(c,l));
    Vector pr=project(l,c.c);
    Vector e=(l.p2-l.p1)/abs(l.p2-l.p1);
    double base=sqrt(c.r*c.r-norm(pr-c.c));

    return make_pair(pr+e*base,pr-e*base);

}

pair<Point,Point> getCrossPoints(Circle c1, Circle c2) {
    double d=abs(c1.c-c2.c);
    double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
    double t=arg(c2.c-c1.c);

    return make_pair(c1.c+polar(c1.r,t+a),c1.c+polar(c1.r,t-a));
}

// IN 2, ON 1, OUT 0
int contains(Polygon g, Point p) {
    int n=g.size();
    bool x=false;
    for(int i=0;i<n;i++) {
        Point a=g[i]-p,b=g[(i+1)%n]-p;
        if(abs(cross(a,b))<EPS && dot(a,b)<EPS) return 1;
        if(a.Y>b.Y) swap(a,b);
        if(a.Y<EPS&&EPS<b.Y&&cross(a,b) > EPS) x=!x;
    }

    return x?2:0;
}

int main() {
    int n;
    cin>>n;
    Polygon g(n);
    for(int i=0;i<n;i++) {
        double x,y;
        cin>>x>>y;
        g[i]=Point(x,y);
    }
    int q; cin>>q;
    while(q-->0) {
        double x,y;
        cin>>x>>y;
        Point p=Point(x,y);
        cout<<contains(g,p)<<endl;
    }
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S; cin >> S;
    int N = S.size();
    S = "0" + S;
    if (S[1] != '1' || S[N] != '0') {
        cout << -1 << '\n';
        return 0;
    }
    for (int i = 1; i + i <= N; i++) {
        if (S[i] != S[N-i]) {
            cout << -1 << '\n';
            return 0;
        }
    }
    int prev = 1, curr = 2;
    for (int i = 1; i + i <= N; i++) {
        cout << prev << ' ' << curr << '\n';
        if (S[i] == '1') prev = curr;
        curr++;
    }
    for (int i = curr; i <= N; i++) {
        cout << prev << ' ' << i << '\n';
    }
    return 0;
}

Measured memory_bytes: 1660
a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
w = a
i = 0
while i < 100:
 if  a%b == c:
  print("YES")
  break
 else:
  a = a+w
  i = i+1
if i ==100:
 print("NO")



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    ll N; cin >> N;
    vector<ll> data(N+1);

    for(int x = 1; x < 101; ++x){
        for(int y = 1; y < 101; ++y){
            for(int z = 1; z < 101; ++z){
                ll n = x*x + y*y + z*z + x*y + y*z + z*x;
                if(n<=N) data.at(n)++;
            }
        }
    }

    rep(i, N) cout << data.at(i+1) << endl;
}

Measured memory_bytes: 3672
import numpy as np
import bisect

def main():
	a,b,q=map(int,input().split())
	INF=10**18
	s=[-INF]+[int(input()) for i in range(a)]+[INF]
	t=[-INF]+[int(input()) for i in range(b)]+[INF]
	X=[int(input()) for i in range(q)]

	for x in X:
		b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)
		res=INF

		for S in [s[b-1],s[b]]:
			for T in [t[d-1],t[d]]:
				d1,d2=abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)
				res=min(res,d1,d2)

		print(res)

def inputList():
	a=list(map(int,input().split()))
	return a

def multisort(li,index):
	return sorted(li,key=lambda x: x[index])

if(__name__=='__main__'):
	main()


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

int main() {
	int N, T[100010], A[100010]; cin >> N;
	for(int i=1; i<=N; ++i) cin >> T[i];
	for(int i=1; i<=N; ++i) cin >> A[i];
	T[0]=0, A[N+1]=1000000001;
	long ans=1, mod=1000000007;
	for(int i=1; i<=N; ++i){
	    if(T[i]==T[i-1] && A[i]==A[i+1]) ans=(ans*min(T[i], A[i]))%mod;
	    else{
	        if(T[i-1]<T[i] && T[i]>A[i]) ans=0;
	        if(A[i]<A[i+1] && A[i]>T[i]) ans=0;
	    }
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = [int(i) for i in input().split()]

A.sort()
S = [A[0]]
for i in range(1, N) :
    S.append(S[-1] + A[i])

for i in range(N - 2, -1, -1) :
    if A[i] > S[i - 1] * 2 :
        break
        
print(N - i)

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

int main()
{
    int n;
    cin >> n;
    vector<int> ans(n);
    for (int i = 1; i < 100; i++)
    {
        for (int j = 1; j < 100; j++)
        {
            for (int k = 1; k < 100; k++)
            {
                int t = i * i + j * j + k * k + i * j + i * k + j * k;
                if (t <= 10000)
                    ans[t - 1]++;
            }
        }
    }
    for (int i = 0; i < n; i++)
        cout << ans[i] << endl;
}


Measured memory_bytes: 3668
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
N, Q = list(map(int, input().split()))
tree = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
counter = [0]*N
p_lis = [0] * Q
x_lis = [0] * Q
for i in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x
stack = deque([0])
visited = [0]*N
visited[0] = 1  # ルートからたどっていく
while stack:
    node = stack.pop()
    for child in tree[node]:
        if visited[child] == 1:
            continue
        stack.append(child)
        visited[node] = 1
        counter[child] += counter[node]


print(*counter)


Measured memory_bytes: 67928
N, D = map(int,input().split())
XY = []
for i in [0]*N:
    XY.append(list(map(int,input().split())))
dD = D ** 2
ans = 0
for j in XY:
    if dD >= j[0] ** 2 + j[1] ** 2:
        ans += 1
print(ans)


Measured memory_bytes: 47024
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n;
    ll k;
    cin >> n >> k;
    vi a(n + 1);
    vector<bool> vis(n + 1, false);

    fo(i, n) cin >> a[i + 1];

    int at = 1;
    vis[at] = true;
    while ( k > 0 ) {
        k--;
        at = a[at];

        if ( vis[at] ) break;
        else vis[at] = true;
    }

    if ( k > 0 ) {
        int cmc = at;
        int tam = 1;
        at = a[at];
        while ( at != cmc ) {
            tam++;
            at = a[at];
        }

        k %= (ll) tam;
        while ( k > 0 ) {
            k--;
            at = a[at];
        }
    }
    cout << at << endl;

    return 0;
}

Measured memory_bytes: 4048
def main():
    N, K = map(int, input().split())
    D = [int(d) for d in input().split()]

    F = []
    for i in range(10):
        if i not in D: F.append(i)

    l = len(str(N))
    cand = [""]
    for _ in range(l):
        temp = []
        for s in cand:
            for f in F:
                temp.append(s+str(f))
        cand = temp

    lv = [int(s) for s in cand]
    for s in sorted(lv):
        if int(s) >= N: return int(s)

    minf = 9
    for f in F:
        if f > 0: minf = min(minf, f)

    cand = sorted(cand)
    return int(str(minf) + cand[0])

if __name__ == '__main__':

    print(main())

Measured memory_bytes: 3700
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.regex;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  writeln(!s.matchFirst(r"^A[a-z]+C[a-z]+$").empty ? "AC" : "WA");
}


Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

ans = 'War'
for i in range(X + 1, Y + 1):
    if max(xs) < i and min(ys) >= i:
        ans = 'No War'

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define vl vector
#define pb push_back
using namespace std;
int main()
{
    ll a,b,i,j,n,k;
    ll m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1==2)
    {
        if(d1==28) cout<<"1";
        else cout<<"0";
    }
    else if(m1<=7)
    {
        if(m1%2 && d1==31) cout<<"1";
        else if(m1%2==0 && d1==30) cout<<"1";
        else cout<<"0";
    }
    else
    {
        if(m1%2 && d1==30) cout<<"1";
        else if(m1%2==0 && d1==31) cout<<"1";
        else cout<<"0";
    }
}

Measured memory_bytes: 3520
#include<stdio.h>
int main()
{
	long int n,s,t,sum,max,d[5000];
	while(scanf("%d",&n) && n)
	{
		max=-100000;
		for(s=0;s<n;s++)
			scanf("%ld",&d[s]);
		for(s=0;s<n;s++)
		{
			sum=0;
			for(t=s;t<n;t++)
			{
				sum+=d[t];
				if(sum > max)
					max=sum;
			}
		}
		printf("%ld\n",max);
	}
	return 0;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

int n, k;
vii edges;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin >> n >> k;
	for (int i = 2; i <= n; ++i) {
		edges.pb(mp(1, i));
	}
	int pairs = (n - 1) * (n - 2) / 2;
	if (k > pairs) {
		cout << "-1\n";
		return 0;
	}
	int diff = pairs - k;
	//db(diff);
	for (int i = 2; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			if (!diff)
				break;
			edges.pb(mp(i, j));
			--diff;
		}
		if (!diff)
			break;
	}
	cout << sz(edges) << '\n';
	for (auto& edge : edges) {
		cout << edge.fs << ' ' << edge.sc << '\n';
	}
	return 0;
}


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

using namespace std;
using Graph = vector<vector<int>>;

int main(){
  int N,M;
  cin >> N >> M;
  Graph G(N);
  vector<int> v;

  for(int i = 0; i < N; i++){
    v.push_back(i);
  }

  for(int i = 0; i < M; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int cnt = 0;
  do{
    for(int i = 0; i < N; i++){
      if(i == N - 1) cnt++;
      else if(count(G[v[i]].begin(),G[v[i]].end(),v[i + 1]) == 0){
        break;
      }
    }
  }while(next_permutation(v.begin()+1,v.end()));

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";
#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	char arr[4];
	cin >> arr;
	if(arr[1] == 'B'){
		cout << "ARC";
	}
	else{
		cout << "ABC";
	}
} 

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

int main() {
  int N;
  int Y;

  cin >> N >> Y;
  Y /= 1000;
  int max = (int)((10 * N - Y) / 9) + 1;
  int x = -1, y = -1, z = -1;
  for (int i = 0; i < max; i++) {
    if((10 * N - Y - 9 * i) % 5 == 0 && N - i - (10 * N - Y - 9 * i) / 5 >= 0) {
      x = i;
      y = (10 * N - Y - 9 * i) / 5;
      z = N - x - y;
      break;
    } 
  }

  cout << z << " " << y << " " << x << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	int t=0,x=0,y=0;
	bool B=1;
	for(int i=0;i<n;i++){
		int T,X,Y;
		cin>>T>>X>>Y;
		int st=T-t;
		int d=abs(X-x)+abs(Y-y);
		if(d>st||(st-d)%2==1) B=0;
		t=T;x=X;y=Y;
	}
	if(B) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

nn = inputs[0][0]

# body
if $debugFlag
end

puts (nn-1)/2


Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int P;
	int Q;
	int R;
	cin >> P;
	cin >> Q;
	cin >> R;

	int ans = min(P + Q, min(Q + R, R + P));

	cout << ans << endl;

	return 0;
}


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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;

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

int H, W; // 縦、横
char maze[20][20]; // 迷路の文字配列

int dh[] = {1, -1, 0, 0};
int dw[] = {0, 0, 1, -1};

int bfs(int sh, int sw) { // スタートする位置を引数
    int d[20][20];  //距離を示すよ
    rep(i, 20) rep(j, 20) d[i][j] = 1000000; //初期化
    d[sh][sw] = 0;

    queue<int> qh; //キューの準備
    queue<int> qw;

    qh.push(sh); //スタートするところのキューを入れる
    qw.push(sw);

    while(qh.size()) { //キューの中身が空っぽに
        int h = qh.front();
        int w = qw.front();
        qh.pop();
        qw.pop();
        for(int i = 0; i < 4; i++) {
            int nh = h + dh[i];
            int nw = w + dw[i];
            if (nh < 0 or nh >= H or nw < 0 or nw >= W) continue;
            if (maze[nh][nw] == '.' and d[nh][nw] == 1000000) {
                d[nh][nw] = d[h][w] + 1;
                qh.push(nh);
                qw.push(nw);
            }
        }
    }

    int ret = 0;
    rep(i, H) rep(j, W) {
        if (maze[i][j] != '#') {
            ret = max(ret, d[i][j]);
        }
    }

    return ret;
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> maze[i][j]; //文字列の受け取り
        }
    }

    int ans = 0;

    for(int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (maze[h][w] != '#') ans = max(ans, bfs(h, w));
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
/*
 * DATE : 2017-06-03
 * Algo :
*/
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define Long                    long long
#define Ulong                   unsigned long long
#define FOR(I,A,B)              for(long long i=0; i < n ; i++ )
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-9
#define F                       first
#define S                       second
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl;
#define Di(x)                   int x; cin>>x
#define in(x)                   input(x)
#define in2(x,y)                input(x), input(y)
#define in3(x,y,z)              input(x), input(y),input(z)
#define ins(x)                  scanf("%s",x)
#define ind(x)                  scanf("%lf",&x)
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)

template<class T > void input(T &x){
    char c = getchar();x = 0;
    for(;(c<48 || c>57);c = getchar());
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
}
inline long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 1e5+5;

long long n,a,b;
long long h[N];

long long find(long long h, long long sum)
{
    long long low = 0, high = sum , ans = 1e18+1;
    while(low <= high ) {
        double mid= (low+high)/2;
        double t = 1.* mid * a + 1.* (sum - mid ) * b;
        if(t >= h ) {
            ans = mid;
            high = mid-1;
        }
        else low = mid+1;
    }
    return ans;
}
bool can(long long turn)
{
    long long m = 0;
    for(int i=0;i<n;i++) {
        long long k = find(h[i],turn );
        if( m + k > turn ) return 0;
        m += k;
    }
    return (m <= turn);
}
int main()
{
    in3(n,a,b);
    for(int i=0;i<n;i++) in(h[i]);
    long long low =0, high = 1e18, mid, ans= -1;
    while(low <= high ) {
        mid = (low+high)/2;
        if(can(mid)) {
            ans = mid;
            high = mid-1;
        }else low = mid+1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int h,w,m;
  cin>>h>>w>>m;
  int x[m],y[m];
  rep(i,0,m){
    cin>>x[i]>>y[i];
    x[i]--;
    y[i]--;
  }
  int a[h],b[w];
  rep(i,0,h) a[i]=0;
  rep(i,0,w) b[i]=0;
  rep(i,0,m){
    a[x[i]]++;
    b[y[i]]++;
  }
  int xx=0;
  rep(i,0,h) xx=max(xx,a[i]);
  int yy=0;
  rep(i,0,w) yy=max(yy,b[i]);
  ll cnt=0;
  rep(i,0,m){
    if(a[x[i]]+b[y[i]]==xx+yy) cnt--;
    else if(a[x[i]]+b[y[i]]==xx+yy+1) cnt++;
  }
  sort(b,b+w);
  rep(i,0,h){
    cnt+=upper_bound(b,b+w,xx+yy-a[i])-lower_bound(b,b+w,xx+yy-a[i]);
  }
  if(cnt==0) cout<<xx+yy-1<<endl;
  else cout<<xx+yy<<endl;
}

Measured memory_bytes: 8304
from collections import defaultdict

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

d = defaultdict(int)

for i in range(n):
    d[a[i]] += 1

ans = 0
for num in d.values():
    ans += num * (num - 1) // 2

for i in range(n):
    num = d[a[i]]
    print(ans - num * (num - 1) // 2 + (num - 1) * (num - 2) // 2)


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

//define ll long long;
//define ar array;

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

    long long n;
    cin >> n;
    long long ans=0;
    // return the answer + 1;
    for (int i = 2; i <= n; i++){ 
        for (int j = i; j <= n; j+=i){
            ans+=j;
        }
    }

    ans += (n*(n+1))/2;
    cout << ans << endl;



    
    
    return 0;
}



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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,c,x,y,ans=10000000001,x1,y1;
	cin>>a>>b>>c>>x>>y;
	for(ll i=0;i<100000001;i+=2){
		x1=i;
		if(x<=i/2)x1=2*x;
		y1=i;
		if(y<=i/2)y1=2*y;
		ans=min(ans,(i*c)+a*(x-x1/2)+b*(y-y1/2));
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

const int mod = 1e9+7;
#define ll long long int
const double epsilon = 1e-7;

ll ma(ll x, ll y){
    if(x>y)return x;
    return y;
}
int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("81 50\n");
    for(int i = 0;i < 40;i++){
        for(int j = 0;j < 50;j++){
            if(a>1 && i%2 + j%2 == 0){
                printf(".");
                a--;
            }else printf("#");
        }
        printf("\n");
    }
    for(int j = 0;j < 50;j++)printf(".");
    printf("\n");
    for(int i = 0;i < 40;i++){
        for(int j = 0;j < 50;j++){
            if(b>1 && i%2 + j%2 == 0){
                printf("#");
                b--;
            }else printf(".");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

const int N = 100000;
const int M = 11;

double dp[N][M] , data[N+1] , ans[N],sum;
int n;

int main(void){
  data[0] = 1.0;
  loop(i,1,M+1)data[i] = data[i-1] * 0.5;
  fill(dp[0],dp[N],0.0);
  dp[0][0] = 1.0;
  rep(i,N){
    rep(j,M){
      if(dp[i][j] > 0.0){
	sum += dp[i][j] * data[j];
	dp[i+1][0] += dp[i][j] * (1.0 - data[j]);
	dp[i+1][j+1] += dp[i][j] * data[j];
      }
    }
    ans[i] = sum;
  }
  while(cin>>n,n)printf("%.3f\n",ans[n-1]);
  return 0;
}

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

int n;
map<ll, ll> m;
ll a[200000];

int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    ll sum = 0;
    ll ans = 0;
    m[0] = 1;
    rep(i,n) {
        sum += a[i];
        if (m[sum] > 0) {
            ans += m[sum];
        }
        m[sum]++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 14336
#include <stdio.h>
int main(void){
  char ch, C;
  for(;;){
  scanf("%c",&ch);
  if(ch == '\n'){
      break;
  }
  else if(ch == ' '){
      printf(" ");
  }
  else if('A' <= ch && ch <= 'Z'){
      C = ch + 32;
      printf("%c",C);
  }
  else if('a' <= ch && ch <= 'z'){
      C = ch - 32;
      printf("%c",C);
  }
  else{
      printf("%c",ch);
  
  }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2044
N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
if a[0] > x:
    ans = a[0] - x
    a[0] = x

for i in range(1,N):
    if a[i-1] + a[i] > x:
        ans += a[i-1] + a[i] - x
        a[i] = x - a[i-1]

print(ans)

Measured memory_bytes: 14252
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    N,=pin()
    S,T=lispin(str)

    for g in zip(S,T):
        print(*g,sep="",end="")
    print()
    
#%%submit!
resolve()

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

queue<char> que;
int arr[26];
int for_sort[26];

int main(){
while(1){//start
	
	int n;
	cin >> n;
	if(n == 0) break;
	for(int i = 0; i < n; i++){
		char tmp;
		cin >> tmp;
		que.push(tmp);
	}
	for(int i = 0; i < 26; i++) arr[i] = 0;
	
	
	//v.resize(26);
	int ans_i;
	char ans_c;
	int flag = 0;
	for(int i = 0; i < n; i++){
		char c = que.front();
		que.pop();
		arr[c - 'A'] += 1;
		int Fi = 0;
		int Se = 0;
		
		//Dump
		for(int j = 0; j < 26; j++){
			for_sort[j] = arr[j];
		}
		sort(for_sort, for_sort + 26);
		Fi = for_sort[25];
		Se = for_sort[24];
		
		if(n-i-1 < Fi - Se and !flag){
			for(int j = 0; j < 26; j++){
				if(Fi == arr[j]){
					flag = 1;
					ans_c = j + 'A';
					ans_i = i + 1;
				}
			}
		}
		//clear
		//for(int j = 0; j < 26; j++) cpy[j] = 0;
	}
	
	
	
	
	sort(arr, arr + 26);
	if(arr[25] == arr[24]) cout << "TIE" << endl;
	else cout << ans_c << " " << ans_i << endl;
	if(!que.empty()) que.pop();
	
}//end	
	return 0;
}


Measured memory_bytes: 3088
import math
a,b,h,m=map(int,input().split())
ang=6*m-30*h-m/2
if ang<0:
    ang*=-1
ang=ang*math.pi/180
#c=math.cos(ang)
#print(c)
r=math.sqrt(a*a+b*b-2*a*b*math.cos(ang))
print(r)


Measured memory_bytes: 62508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;


int main() {
	int N; cin >> N;
	rep (i, N) {
		for (int j = i + 1; j < N; j++) {
			
			for (int k = 0; true; k++) {
				if (((i >> k) & 1) != ((j >> k) & 1)) {
					cout << k + 1 << " ";
					break;
				}
			}
		}
		cout << endl;
	}

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int D, G;
vector<pii> P;
//=============================
void input()
{
    cin >> D >> G;
    P.resize(D);
    rep(i, D)
    {
        cin >> P[i].first >> P[i].second;
    }
}

void solve()
{


    int ans = INF;
    for (int i = 0; i < (1<<D); ++i)
    {
        bool br = false;
        int score = 0;
        int ans_sub = 0;
        for (int j = 0; j < D; ++j)
        {
            if ((i >> j) & 1LL)
            {
                ans_sub += P[j].first;
                score += P[j].second + P[j].first * 100 * (j + 1);
            }
        }
        if (score >= G)
        {
            //debug(ans_sub);
            ans = min(ans, ans_sub);
            continue;
        }

        for (int j = D - 1; j >= 0; --j)
        {
            if (br)
            {
                break;
            }

            if (!((i >> j) & 1LL))
            {
                for (int k = 0; k < P[j].first; ++k)
                {
                    if (score >= G)
                    {
             //           debug(ans_sub);
                        ans = min(ans, ans_sub);
                        br = true;
                        break;
                    }
                    else
                    {
                        ans_sub += 1;
                        score += (j + 1) * 100;
                    }
                }
            }
        }
    }

    cout << ans << endl;
}

//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int A, B;
  cin >> A >> B;
  cout << (A-1)*(B-1) <<endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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


int N, K;
using Graph = vector<vector<int>>;

ll dfs(Graph& G, int now, int from) {
  //cout << point << "\n";
  //cout << ans << "\n";

  int can_use_color_n;
  if (from == 0) {
    can_use_color_n = K-1;
  } else {
    can_use_color_n = K-2;
  }
  
  if (K < G[now].size()) {
    return 0;
  }

  ll tmp = 1;
  for (auto next_v : G[now]) {
    if (next_v == from) continue;

    tmp *= can_use_color_n;
    can_use_color_n--;
    tmp %= MOD;
  }
  for (auto next_v : G[now]) {
    if (next_v == from) continue;

    tmp *= dfs(G, next_v, now);
    tmp %= MOD;
  }

  return tmp;
}

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

  Graph G(N+1);

  Rep(i, N-1) {
    int a, b;
    cin >> a >> b; 
    G[a].push_back(b);
    G[b].push_back(a);
  }

  ll ans = K * dfs(G, 1, 0);
  ans %= MOD;

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

Measured memory_bytes: 11520
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl (wrds toInt) >>= print

solve :: [Int] -> Int
solve = f . (>= 1000) . sum . zipWith (*) [1,5,10,50,100,500]
  where f True = 1
        f False = 0

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
#include <string>
#include <bitset>
#include <cassert>
using namespace std;

int main()
{
	long long x, k, d;
	cin >> x >> k >> d;
	long long jumps = 0;
	if (abs(x) > d) {
		if (x >= 0) {
			jumps = x / d;
			if (k >= jumps) {
				k -= jumps;
				x = x % d;
			}
			else {
			
				cout << abs(x - d * k);
				return 0;
			}

		}
		else {
		
			jumps = abs(x) / d;
			if (k >= jumps) {
				k -= jumps;
				x = (-1) * (abs(x) % d);
			}
			else {
				
				cout << abs(x + d * k);
				return 0;
			}
		}
	}
	assert(abs(x) <= d);
	if (k%2==0) cout << abs(x);
	else {
		if (x < 0) cout <<  abs(x + d);
		else cout <<  abs(x - d);
	}
}


Measured memory_bytes: 3608
import sys

s = sys.stdin.readline()
t = sys.stdin.readline()

# dp[i][j] = LCS(s[:i],t[:j])
sLen, tLen = len(s),len(t),
dp = [ [( 0 , -1 )]*(tLen+1)  for _ in range(sLen+1) ]
for i in range(1,sLen+1):
    for j in range(1,tLen+1):
        comp = [ dp[i][j-1][0],dp[i-1][j-1][0]+int(s[i-1]==t[j-1]),dp[i-1][j][0]]
        argmax = comp.index(max(comp))
        dp[i][j] = ( comp[argmax] , argmax )

ans = ""
i,j = sLen, tLen
for _ in range(sLen+tLen):
    if dp[i][j][1] == 0:
        j -= 1
    elif dp[i][j][1] == 1:
        ans += s[i-1]
        i -= 1
        j -= 1
    elif dp[i][j][1] == 2:
        i -= 1
    else:
        break

print(ans[::-1])

Measured memory_bytes: 307848