akhauriyash/Code-Regression huggingface dataset:
struct{
	char name[21];
	int score;
}team[10];
main(){
	int N,n,i,w,l,d,score,second=0;
	char name[21];
	for(;scanf("%d",&N),N;){
		for(n=0;n<N;n++){
			scanf("%s%d%d%d\n",name,&w,&l,&d);
			score=w*3+d;
			for(i=0;i<n&&team[i].score>=score;i++);
			memmove(team+i+1,team+i,sizeof(*team)*(n-i));
			strcpy(team[i].name,name);
			team[i].score=score;
		}
		if(second)
			puts("");
		for(i=0;i<N;i++)
			printf("%s,%d\n",team[i].name,team[i].score);
		second=1;
	}
	exit(0);
}

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

int main(){
  int h[301],w[301];
  for(int i=0;i<301;++i){
    cin >> h[i] >> w[i];
    if(h[i] == 0 && w[i] == 0)break;
  }
  for(int i=0;i<301;++i){
    if(h[i] == 0&&w[i] == 0)break;
    for(int j=0;j<h[i];j++){
      for(int k=0;k<w[i];k++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main(){
  int A,B,C,K,a,c;
  cin>> A >> B >> C >> K;
  if(A<=K){
    a=A;
  }else{
    a=K;
  }
  if(K-A-B>0){
    c=K-A-B;
  }else{
    c=0;
  }
  cout<< a-c <<endl;
  return 0;
}

Measured memory_bytes: 3188
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define mod 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

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


main()
{
    optimize();
int n,i,j=0;
cin>>n;
ll a[n+1];
for(i=1;i<=n;i++)
{
    cin>>a[i];
}
sort(a+1,a+n+1);
for(i=1;i<n;i++)
{
    j=j+a[i];
}
if(a[n]<j)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;















    return 0;
}











































Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 2000009;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
ll mod = 1e9+7;
ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
// ll fact[N];


// ll ncr(ll n,ll r){
//      return (((fact[n]*powm(fact[r],mod-2))%mod)*powm(fact[n-r],mod-2))%mod;
// }
 int main() {   
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
     // #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
     // #endif
     ll t = 1;
     // cin>>t;
     while(t--){
          ll n;cin>>n;ll a[n];
          ll ct[2002];
          memset(ct,0,sizeof(ct));
          for(int i = 0;i<n;i++){
               cin>>a[i];
               ct[a[i]]++;
          }
          for(int i = 1;i<2002;i++){
               ct[i]+=ct[i-1];
               // cout<<ct[i]<<" ";
          }
          ll ans = 0;
          for(int i = 0;i<n;i++){
               for(int j = i+1;j<n;j++){
                    ll temp=ct[a[i] + a[j] - 1] - ct[abs(a[i] - a[j])];
                    if(a[i]>abs(a[i] - a[j])  &&  a[i]<a[i] + a[j] ){
                         temp--;
                    }
                    if(a[j]>abs(a[i] - a[j])  &&  a[j]<a[i] + a[j] ){
                         temp--;
                    }
                    // cout<<a[i]<<" "<<a[j]<<" "<<temp<<'\n';
                     ans+=temp;
               }
              
          }
          ans = ans/3;
          cout<<ans;
     }
}            


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 22 16:34:05 2019

@author: Yamazaki Kenichi
"""

n = int(input())
A = [list(map(int,input().split())) for i in range(n)]

T = [[0 for i in range(n)] for i in range(n)]

for c in A:
    if c[1] != 0:
        for i in range(c[1]):
            T[c[0]-1][c[i+2]-1] = 1

for c in T:
    print(' '.join(map(str,c)))


Measured memory_bytes: 5692
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] w = new int[n];
    for(int i = 0; i < n; i++) {
      w[i] = sc.nextInt();
    }
    int[] s = new int[n];
    s[0] = w[0];
    for(int i = 1; i < n; i++) {
      s[i] = s[i - 1] + w[i];
    }
    int ans = 1000000;
    for(int i = 0; i < n - 1; i++) {
      int a = s[i];
      int b = s[n - 1] - a;
      ans = Math.min(ans, (int)Math.abs(a - b));
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
ans,min=0,float('inf')
for i in range(n):
    if min>abs(a-(t-h[i]*0.006)):
        min=abs(a-(t-h[i]*0.006))
        ans=i+1
print(ans)

Measured memory_bytes: 3060
import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]) = {
    val n = readLine.split(" ")(0).toInt
    val c = readLine.split(" ").map(_.toInt)
    val minVal = (0 to n+1).toArray

    for( i <- 2 to n+1 ) {
      for( j <- c ) {
        if(j<=i && minVal(i-j) + 1 < minVal(i)) {
          minVal(i) = minVal(i-j)+1
        }
      }
    }
    println(minVal(n))
  }
}

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

int main(){
  int W[10],K[10];
  for(int i=0;i<10;i++) cin>>W[i];
  for(int i=0;i<10;i++) cin>>K[i];
  sort(W,W+10);
  sort(K,K+10);

  int max1,max2;
  max1=max2=0;

  max1=W[9]+W[8]+W[7];
  max2=K[9]+K[8]+K[7];

  cout<<max1<<" "<<max2<<endl;
  return 0;
}

Measured memory_bytes: 1180
a,b,c,x,y=map(int,input().split())
if x>=y:
    if c*2<=min(a,b):
        print(c*2*x)
    elif c*2<=max(a,b):
        if a>=b:
            print(c*2*x)
        else:
            print(c*2*y+a*(x-y))
    elif c*2<=a+b:
        print(c*2*y+a*(x-y))
    else:
        print(a*x+b*y)
else:
    if c*2<=min(a,b):
        print(c*2*y)
    elif c*2<=max(a,b):
        if a<=b:
            print(c*2*y)
        else:
            print(c*2*y+b*(y-x))
    elif c*2<=a+b:
        print(c*2*x+b*(y-x))
    else:
        print(a*x+b*y)

Measured memory_bytes: 3064
a,b,k = map(int,input().split())
if a+2*k-1>=b:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for i in range(b-k+1,b+1):
    print(i)
  

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  for (int i = 0; i < N; i++){
    cin >> x[i] >> y[i] >> h[i];
  }
  int s;
  for (int i = 0; i < N; i++){
    if (h[i] > 0){
      s = i;
      break;
    }
  }
  for (int i = 0; i <= 100; i++){
    for (int j = 0; j <= 100; j++){
      int H = h[s] + abs(y[s] - i) + abs(x[s] - j);
      bool ok = true;
      for (int k = 0; k < N; k++){
        if (h[k] != max(H - abs(y[k] - i) - abs(x[k] - j), 0)){
          ok = false;
        }
      }
      if (ok){
        cout << j << ' ' << i << ' ' << H << endl;
      }
    }
  }
}

Measured memory_bytes: 3560
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)

ull calc_sum(vector<ull> a){
	if(a.size()==1) return a[0];
	vector<ull> b=a, c=a;
	b.erase(b.begin());
	ull tmp=10*c[0]+c[1];
	c.erase(c.begin(), c.begin()+2);
	c.insert(c.begin(), tmp);
	return pow(2,a.size()-2)*a[0]+calc_sum(b)+calc_sum(c);
}

int main(){
	string s;
	cin >> s;
	vector<ull> a;
	for(int i=0; i<s.length(); i++){
		char t=s[i];
		a.push_back(atoi(&t));
	}
	cout << calc_sum(a) << endl;
	return 0;
}

Measured memory_bytes: 256
def mod_factorial(N, d):
    ans = 1
    for i in range(1,N+1):
        ans = (ans * i) % d
    return ans

d = 10**9 + 7
N = int(input())
list_co = list(map(int, input().split()))

ans = 1      
for i, x in enumerate(list_co):
    if x < 2*(i+1) -1: #(i+1) : robot number, x : coordinate of robot(i+1)
        ans *= (i+1)
        list_co.pop(i-1)
ans = (ans * mod_factorial(len(list_co),d)) % d
print(ans)


Measured memory_bytes: 14052
r, c = [int(i) for i in input().split(" ")]
s_row = [0 for x in range(c + 1)]

for i in range(r):
    row = [int(n) for n in input().split(" ")]
    row.append(sum(row))
    print(" ".join( [ str(s) for s in row ] ) )
    s_row = [ x + y for x, y in zip(s_row, row)]
print(" ".join( [str(s1) for s1 in s_row] ))

Measured memory_bytes: 7640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		StringBuilder str = new StringBuilder(sc.nextLine());

		int N = sc.nextInt();
		for (int i = 0; i < N; i++) {
			String order = sc.next();
			int a = sc.nextInt();
			int b = sc.nextInt() + 1;

			if (order.equals("print")) {
				System.out.println( str.substring(a, b) );
			} else if (order.equals("reverse")) {
				str.replace(a, b, new StringBuilder(str.substring(a, b)).reverse().toString());
			} else {
				String s = sc.next();
				str.replace(a, b, s);
			}
		}

	}
}


Measured memory_bytes: 28948
import java.util.*;
 
public class Main{
    public static  void main(String[]args){
        Scanner sc = new Scanner(System.in);
        long N=0;
        long K=0;
        N=sc.nextLong();
        K=sc.nextLong();
        long m=0;
        m=N/K;
        long min=0;
        min=Math.abs(N-m*K);
        if(min>Math.abs(N-(m-1)*K))
        min=Math.abs(N-(m-1)*K);
        else if(min>Math.abs(N-(m+1)*K))
        min=Math.abs(N-(m+1)*K);
        System.out.println(min);
    }
}

Measured memory_bytes: 20820
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s; cin >> s;
    int a = (s[0] - '0') * 10 + s[1] - '0';
    int b = (s[2] - '0') * 10 + s[3] - '0';

    string res = "";
    if (0 < a && a <= 12) {
        if (0 < b && b <= 12) {
            res = "AMBIGUOUS";
        } else {
            res = "MMYY";
        }
    } else {
        if (0 < b && b <= 12) {
            res = "YYMM";
        } else {
            res = "NA";
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    string s;
    cin>> s;
    vi sa = suffix_array(s);
    ll answer = 1LL * s.size() * (s.size() + 1) / 2;
    for(auto x: lcp_array(s, sa)) answer -= x;
    cout << answer << endl;
}

Measured memory_bytes: 15652
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow

}


//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor_ver2(int n, map<int, int> res) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n]++;
	return res;
}

struct Mystr
{
	int a, b, c;
};

bool cmp(const Mystr &X, const Mystr &Y) {
	return X.c>Y.c;
}


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

	int N, M;
	cin >> N >> M;

	int ans = 0;

	if (N >= M / 2) {
		//cが足りない
		ans = min(N, M / 2);
	}
	else if (N < M / 2) {
		//cが余る
		ans = N;
		M -= N * 2;
		ans += M / 4;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

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

int main(){
  int n; cin >> n;
  vector<ll> t(n);
  rep(i, n) cin >> t[i];
  
  ll ans = t[0];
  for(int i = 1; i < n; i++){
    ans = lcm(ans,t[i]);
  }

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


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        boolean[] rec = new boolean[26];
        for(int i=0;i<S.length();i++){
            int cur = S.charAt(i)-'a';
            if(rec[cur]){
                System.out.println("no");
                System.exit(0);
            }
            else rec[cur]=true;
        }
        System.out.println("yes");
    }
}
 

Measured memory_bytes: 21844
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

// 素数判定
bool isprime(ll  n){
	if (n < 2) return false;
	else if (n == 2) return true;
	else if (n % 2 == 0) return false;
	else
		for (int i = 3; i*i <= n; i++)
			if (n%i == 0) return false;

	return true;
}

signed main(){

	int n;
	int ans = 0;
	
	cin >> n;
	for (int i = 0; i < n; i++){
		int x;
		cin >> x;
		if (isprime(x)) ans++;
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3072
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m, d = map(int, read().split())
if d == 0:
    print((m - 1) / n)
else:
    print(2 * (n - d) * (m - 1) / (n ** 2))


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

bool p[300000];

void pcalc(){
    rep(i,300000) p[i] = i<2? false: true;
    rep(i,sqrt(300000))if(p[i])for(int j = i * 2; j < 300000; j += i)p[j] = false;
}

int main() {
    int n;
    pcalc();
    while(cin >> n, n){
	int ans = 0;
	repi(i,n+1,2*n+1)if(p[i]) ans++;
	cout << ans << endl;
    }
    return 0;
}

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

#define rep(i, x, n) for(int i=(x);i<(n);i++)
#define reps(i, x, n) for(int i=(x);i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;
//八方向を見るのに使うと便利(楽)
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  lol t, ans;
  cin >> ans;
  rep(i, 1, n){
    cin >> t;
    ans = lcm(ans, t);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3636
// ref. https://img.atcoder.jp/ddcc2020-qual/editorial.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll m;
  cin >> m;
  ll n = 0; // sum of digit
  ll s = 0; // sum of number
  rep(i, m) {
    ll d, c;
    cin >> d >> c;
    s += d * c;
    n += c;
  }

  ll ans = n-1 + (s-1)/9;
  cout << ans << endl;
}


Measured memory_bytes: 256
# include <iostream>
# include <stack>
# include <cstring>

typedef std::pair<int, int> P;

constexpr int INF = (int)1e7;
constexpr int MAX = 100;

int w, h;
int board[MAX][MAX];
P start, goal;
int n;
int d[MAX][MAX], dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };

bool dfs(P s, P g) {
	bool res = false;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			d[i][j] = INF;
	std::stack<P> stk;
	stk.push(s);
	d[s.second][s.first] = 0;
	while (!stk.empty()) {
		P p = stk.top(); stk.pop();
		if (p == g) {
			res = true;
			break;
		}

		for (int i = 0; i < 4; ++i) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if (0 <= nx&&nx < w &&
				0 <= ny&&ny < h&&
				d[ny][nx] == INF&&board[ny][nx] == board[p.second][p.first]) {
				d[ny][nx] = d[p.second][p.first] + 1;
				stk.push(P(nx, ny));
			}
		}
	}
	return res;
}

int main() {
	while (1) {
		std::cin >> w >> h;
		if (w + h == 0)
			break;
		std::memset(board, 0, sizeof(board));

		std::cin >> start.first >> start.second
			>> goal.first >> goal.second >> n;
		--start.first;
		--start.second;
		--goal.first;
		--goal.second;
		int c, d, x, y;
		for (int i = 0; i < n; ++i) {
			std::cin >> c >> d >> x >> y;
			for (int i = 0; i < 4; ++i) {
				for (int j = 0; j < 2; ++j) {
					int& a = (d) ? board[y - 1 + i][x - 1 + j] : board[y - 1 + j][x - 1 + i];
					a = c;
				}
			}
		}

		if (dfs(start, goal))
			std::cout << "OK" << std::endl;
		else
			std::cout << "NG" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3180
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn readu() -> usize {
    read::<usize>()
}

#[allow(dead_code)]
fn readi() -> i32 {
    read::<i32>()
}

fn main() {
    input! {
        a: usize, b: usize, k: usize,
    }
    let mut c: usize = 0;
    let mut i = 100;
    while i > 0 {
        if a % i == 0 && b % i == 0 {
            c += 1;
            if c == k {
                println!("{}", i);
                break;
            }
        }
        i -= 1;
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
using namespace std;




int main(){
ll n,w,h;
ll ans=0;
cin>>h>>w;
string ue(w+2,'#');
vector<string> s(h);
cout<<ue<<endl;

for(ll i=0;i<h;i++)cin>>s[i];


for(ll i=0;i<h;i++){
cout<<"#";
cout<<s[i];
cout<<"#"<<endl;
}
cout<<ue<<endl;



return 0;

}


Measured memory_bytes: 256
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            for (int j = -1; j <= 1; j++) {
                int num = a[i] + j;
                int count = map.getOrDefault(num, 0) + 1;
                map.put(num, count);
            }
        }
        System.out.println(Collections.max(map.values()));
    }
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if( a <= b) {
        for(int i =0; i<b; i++) cout << a;
    }
    else {
        for(int i =0; i <a ;i++) cout << b;
    }

    cout << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
  int n,i,j,min,c[60][30]={};
  char s[60];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    for(j=0;s[j];j++)c[i][s[j]-'a']++;
  }
  for(i=0;i<26;i++){
    min=1000;
    for(j=0;j<n;j++){
      if(min>c[j][i])min=c[j][i];
    }
    for(j=0;j<min;j++)printf("%c",i+'a');
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
#include<stack>
#include<cstring>
#include<string.h>
#include<cmath>
using namespace std;
typedef long long ll;

int main(){
  int n;
  ll a[300005],ans=0;
  scanf("%d",&n);
  for(int i=0;i<3*n;i+=3){
    scanf("%lld %lld %lld",&a[i+0],&a[i+1],&a[i+2]);
  }  
  sort(a,a+3*n);
  for(int i=3*n-1;i>n;i-=2){
    ans+=a[i-1];
  }
  
  printf("%lld\n",ans);

  return 0;
}


Measured memory_bytes: 2560
k,x=map(int,input().split())
l=[]
if x-k>-1000000 and x+k<1000000:
  l=list(range(x-k+1,x+k))
elif x-k<=-1000000:
  l=range(-1000000,x+k)
elif x+k>=1000000:
  l=range(x-k+1,1000000+1)
for i in l:
  print(str(i)+' ',sep='',end='')

Measured memory_bytes: 3064
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};
const main=()=>{
  let [a,b]=tnn(2)
  let d=tnn(a)
  for(let i=0;i<a;i++)b-=d[i]
  while(true){
    b-=min(...d)
    if(b>=0)a++
    if(b<=0){
      to(a)
      return
    }
  }
}
main()


Measured memory_bytes: 10176
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int N;
	cin>>N;
	int result = 180 * N - 360;
	cout<<result<<endl;
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-9)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

double f(double a, double b, double theta) {
    if (theta > PI/2.0 - EPS) return 0.0;
    double res = 0.0;
    if (tan(theta) <= b/a) {
        res = (a*a*b - a*a*a*tan(theta)/2.0);
    }
    else {
        res = a*b*b/tan(theta)/2.0;
    }
    return res;
}

int main(){
    double a, b, x;
    cin >> a >> b >> x;
    double ok = PI / 2.0, ng = 0.0;
    while (fabs(ok-ng) >= EPS) {
        double mid = (ok+ng) / 2.0;
        if (f(a, b, mid) < x) ok = mid;
        else ng = mid;
    }
    cout << fixed << setprecision(7) << (ok/PI*180.0) << endl;
    return 0;
}


Measured memory_bytes: 4136
import heapq as hq
n = int(input())
arr = []
stack = []
for i in range(n):
    arr.append(int(input()))
    hq.heappush(stack, -arr[-1])

first = -hq.heappop(stack)
second = - hq.heappop(stack)

for i in arr:
    print(first if i != first else second)

Measured memory_bytes: 20528
#include<stdio.h>
#include<string.h>

int main(void)
{
  //文字列Sを入力
  char s[11];
  scanf("%s",s);

  //文字列の長さをslenとする
  int slen = strlen(s);
  
  //計算開始
  int i,j,cnt,ans=0;
  for(i=0;i<slen;i++){

    //cntを初期化  
    cnt=0;

    //s[i]がA,C,G,Tのいずれかであるか確認
    for(j=i;j<slen;j++){
      if((s[j]=='A')||(s[j]=='C')||(s[j]=='G')||(s[j]=='T'))
        cnt++;
      else
        break;
    }
    if(cnt>ans)
      ans=cnt;
    i+=cnt;
  }

  printf("%d\n",ans);
  return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int t , n;
int x , y;
int a[MAXX];
string s;

int main()
{
    _FastIO;

    cin >> n;
    while(n--){
        cout << "ACL";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3604
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-100
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
//	file();
	fast();
	ll a, b, n; 
	cin >> a >> b >> n;
	ll x = (n + 1) / b;
	x = x * b - 1;
	if (n < b)
		x = n;
	cout << (a * x) / b - a * (x / b) << endl;
	return 0;
}

Measured memory_bytes: 3640
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque

def gcd(a, b):
    """最大公約数"""
    a, b = (a, b) if a >= b else (b, a)
    if b == 0:
        return a
    return gcd(b, a % b)


# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, X, x):
    x_abs = [abs(X - xi) for xi in x]
    ans = x_abs[0]
    for xi in x_abs[1:]:
        ans = gcd(ans, xi)
    print(ans)


if __name__ == '__main__':
    N, X = map(int, input().split())
    x = [int(i) for i in input().split()]
    solve(N, X, x)

    # # test
    # from random import randint
    # from func import random_str
    # N, X = 10 ** 5, randint(1, 10 ** 9)
    # x = [randint(1, 10 ** 9) for _ in range(N)]
    # solve(N, X, x)


Measured memory_bytes: 19908
#include <bits/stdc++.h>
using namespace std;
#define int long long
int A[10],B[10],MOD[10]={574230854,342230854,578930854,598343854,574390854,574123454,574230854,543210854,574123454,575670854};
int pw(int n,int k,int mod){
  int res=1;
  while(k){
    if(k&1)res*=n;res%=mod;
    n*=n;n%=mod;
    k>>=1;
  }
  return res;
}

signed main(){
  int n;cin>>n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  vector<int> ac(n),bc(n);
  for(int i=0;i<n;i++)ac[i]=a[(i+1)%n]^a[i];
  for(int i=0;i<n;i++)bc[i]=b[(i+1)%n]^b[i];
  int asum=0,bsum=0;
  for(int i=0;i<n;i++)asum+=ac[i];
  for(int i=0;i<n;i++)bsum+=bc[i];
  for(int i=0;i<10;i++){
    int now=1;
    for(int j=0;j<n;j++){
      A[i]+=now*ac[j];A[i]%=MOD[i];
      B[i]+=now*bc[j];B[i]%=MOD[i];
      now*=i+2;now%=MOD[i];
    }
  }
  for(int i=0;i<n;i++){
    bool f=true;
    for(int j=0;j<10;j++)if(A[j]!=B[j])f=false;
    if(f)cout<<i<<" "<<(a[i]^b[0])<<endl;
    for(int j=0;j<10;j++){
      B[j]*=j+2;B[j]-=pw(j+2,n,MOD[j])*bc[n-1-i];B[j]+=bc[n-1-i];
      B[j]%=MOD[j];B[j]+=MOD[j];B[j]%=MOD[j];
    }
  }
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
int main()
{
    short R;
    cin >> R;
    if (R < 1200)
    {
        cout << "ABC" << endl;
    }
    else if (R < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i;
  ll k,w[100005],d[100005];
  
  cin >> n >> k;
  for (i=0;i<n;i++) cin >> w[i] >> d[i];
  
  ll l,r,mid,t;
  l=0;
  r=2e18;
  while (r-l>1){
    mid=(l+r)/2;
    t=0;
    for (i=0;i<n;i++){
      if (mid>=w[i]) t+=(mid-w[i])/d[i]+1;
    }
    if (t>=k) r=mid;
    else l=mid;
  }
  
  cout << r << endl;
  
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 50;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int n = s.length();
	if(s[0] == s[n-1])
	{
		if(n % 2)
		{
			cout << "Second" << endl;
		}
		else
		{
			cout << "First" << endl;
		}
	}
	else
	{
		if(n % 2)
		{
			cout << "First" << endl;
		}
		else
		{
			cout << "Second" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)
 
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;
 
inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
 
 int n;
 vector<vector<int>>g(210);
 vector<int>col(210,0);
//二部グラフのチェック
 bool is_bipartite(int x,int c){
     //始点を色1で塗る
     col[x]=c;
     for(auto nx:g[x]){
         if(col[nx]==c)return false;
         if(col[nx]==0 && !is_bipartite(nx,-c))return false;
     }
     return true;
 }

 int main(){
     cin>>n;
     rep(i,n)rep(j,n){
         char t;cin>>t;
         if(t=='1')g[i].emplace_back(j);
     }

     bool check=is_bipartite(0,1);
     if(!check){
         print(-1);
         return 0;
     }
    int ans=0;
    rep(i,n){
        vector<int>dists(n,INF);
        //最初の視点は集合1だから1とする
        dists[i]=1;
        queue<int>q;
        q.push(i);
        /*queueを用いた幅優先探索で
        頂点1を始点とした時のグラフの直径を
        求める*/
        while(!q.empty()){
            int x=q.front();
            q.pop();
            for(auto nx:g[x]){
                if(dists[nx]>dists[x]+1){
                    dists[nx]=dists[x]+1;
                    q.push(nx);
                }
            }
        }
        /*もっとも遠い点(終点)の距離+1=集合の個数*/
        ans=max(ans,*max_element(dists.begin(),dists.end()));
    }
    print(ans);

    return 0;

 }

Measured memory_bytes: 512
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

a = input()
if a == "A":
    print("T")
if a == "T":
    print("A")
if a == "C":
    print("G")
if a == "G":
    print("C")

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

int main() {
  int n,x,t,count=0;
  cin >> n >> x >> t;
  
  while(n>x){
    n-=x;
    count+=t;
  }
  
  cout << count+t << endl;
  
  return 0;
  
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <set>
#include <unordered_set>

using namespace std;

int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    int q;
    cin>>q;
    vector<set<int>> p(256);
    for (int i=0;i<s.size();++i){
        p[s[i]].emplace(i);
    }
    int t, i, l, r;
    char c;
    for (int qq=0;qq<q;++qq){
        cin>>t;
        if (t==1) {
            cin>>i>>c;
            --i;
            p[s[i]].erase(i);
            p[c].insert(i);
            s[i]=c;
        } else {
            cin>>l>>r;
            --l;
            --r;
            int cnt=0;
            for (int j=0;j<256;++j){
                if (!p[j].empty()){
                    auto b = p[j].lower_bound(l);
                    if (b != p[j].end() && l <= *b && *b <= r) {
                        ++cnt;
                    }
                }
            }
            cout << cnt <<endl;
        }
    }
}

Measured memory_bytes: 25988
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String[] split = reader.readLine().split(" ");
    int a = Integer.parseInt(split[0]);
    int b = Integer.parseInt(split[1]);
    int c = Integer.parseInt(split[2]);
    System.out.println(c + " " + a + " " + b);
  }
}


Measured memory_bytes: 22612
#D
#https://tech-kyopro.com/atcoder-abc126-d

import sys
sys.setrecursionlimit(500*500)
n = int(input())
edges = [list(map(int,input().split())) for _ in range(n-1)]
#頂点iと隣接する頂点とその距離を格納[["隣接する頂点","その距離"]]
a = [[] for _ in range(n+1)]

for i in edges:
    a[i[0]].append([i[1],i[2]])
    a[i[1]].append([i[0],i[2]])
    
#頂点1からの距離をdepth
depth = [-1 for _ in range(n+1)]
depth[0] = 0

def dfs(a,s):
    for v in a[s]:
        if depth[v[0]] == -1:
            depth[v[0]] = depth[s] + v[1]
            dfs(a,v[0])
            
dfs(a,1)

for d in depth[1:]:
    if d % 2 == 0:
        print(0)
    else:
        print(1)


Measured memory_bytes: 102096
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
  int N,L,k,sum=0,s=1000;
  cin>>N>>L;
  int a[N];
  for(int i=1;i<=N;i++){
    a[i]=L+i-1;
    sum+=a[i];
    s=min(s,abs(a[i]));
    if(s==abs(a[i])) k=i;
  }
  cout<<sum-a[k]<<endl;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

ll f(ll x) {
    // 110
    // 101
    // 100
    // 011
    // 010
    // 001
    // 000

    ll sum = ((x + 1) / 2) % 2;

    for(int i = 1; i < 50; i++) {
        if (((x + 1) / (1LL << i)) % 2 == 0) continue;
        if (((x + 1) % (1LL << (i + 1))) % 2 == 1) {
            sum |= 1LL << i;
        }
    }

    return sum;
}

void solve() {
    ll A, B;
    cin >> A >> B;
    
    cout << (f(B) ^ f(A - 1)) << endl;
    
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
//
// Created on 2020/02/09.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {

    string s;
    cin>>s;

    for (int i = 0; i < s.size(); ++i) {
        cout<<"x";
    }

    cout<<endl<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
string str;
int ans;
int main()
{
	cin >> str;
	int l = str.length();
	for (int i = 1;i < l;i++)
	{
		if (str[i] != str[i-1]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static final int R = 0;
  static final int G = 1;
  static final int B = 2;

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    String s = sc.next();
    int rgb[] = new int[n];
    long rCount = 0;
    long gCount = 0;
    long bCount = 0;
    for (int i = 0; i < n; i++) {
      char c = s.charAt(i);
      if (c == 'R') {
        rgb[i] = R;
        rCount++;
      } else if (c == 'G') {
        rgb[i] = G;
        gCount++;
      } else if (c == 'B') {
        rgb[i] = B;
        bCount++;
      }
    }
    long condition1 = rCount * gCount * bCount;
    long ans = condition1;
    for (int i = 0; i < n - 2; i++) {
      for (int j = i + 1; j < n - 1; j++) {
        int k = (j + 1) + (j + 1) - (i + 1) - 1;
        if (k >= n) {
          continue;
        }
        if (rgb[i] != rgb[j] && rgb[j] != rgb[k] && rgb[i] != rgb[k]) {
          ans--;
        }
      }
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 36088
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
struct edge{
    ll to;
    ll cost;
    edge(ll t, ll c){
        to = t;
        cost = c;
    }
};

//* dijkstra algorithm with adjacency list
void dijkstra(vector<vector<edge> > &G, vll &dist, ll s){
    fill(dist.begin(), dist.end(), INF);
    priority_queue<pll, vector<pll>, greater<pll> > que;
    dist[s] = 0;
    que.push(pll(0, s));
    while(!que.empty()){
        ll score = que.top().first;
        ll u = que.top().second;
        que.pop();
        for(ll i=0; i< G[u].size(); i++){
            edge e = G[u][i];
            if(dist[e.to] > score + e.cost){
                dist[e.to] = score + e.cost;
                que.push(pll(dist[e.to], e.to));
            }
        }
    }
    return;
}

void solve(long long N, long long X, long long Y){
    X--; Y--;
    vector<vll> matDist(N);
    vector<vector<edge> > G(N);
    REP(i, N-1){
        G[i].push_back(edge(i+1, 1));
        G[i+1].push_back(edge(i, 1));
    }
    G[X].push_back(edge(Y, 1));
    G[Y].push_back(edge(X, 1));

    vll vecDist(N);
    REP(i, N){
        dijkstra(G, vecDist, i);
        matDist[i]=vecDist;
    }
    vll ans(N, 0);
    REP(i, N){
        for(ll j=i+1; j < N; j++){
            ans[matDist[i][j]]++;
        }
    }
    REP(i, N-1){
        cout<<ans[i+1]<<endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(N, X, Y);
    return 0;
}


Measured memory_bytes: 31744
import math

def try_square_root_naive(n):
    m = int(n**.5)
    return m if abs(m*m - n) < 1e-6 else None

a, b = input().split()
# print(math.sqrt(int(a + b)))
result = try_square_root_naive(int(a + b))
if result != None:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define str string
#define deb_arr(arr,n) for(ll i=0;i<(n);i++){ cout << (arr)[i] << " ";}
#define in_arr0(arr,n) for(ll i=0;i<(n);i++){ cin >> (arr)[i]; }
#define in_arr1(arr,n) for(ll i=1;i<=(n);i++){ cin >> (arr)[i];}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define vll vector<ll> 
#define fr(n) for(i=0;i<(n);i++)
#define fr1(n) for(i=1;i<=(n);i++)
#define pll pair<ll,ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define IN(a,b) ((a).find(b)!=(a).end())
#define pb push_back
#define mkp make_pair
#define PI M_PI
#define INF 1e18
#define deb(x) if(ON) cout << #x <<" : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL),cout.tie(NULL)
#define ON !false
ll dx[]={0,-1,0,1};
ll dy[]={1,0,-1,0};
const ll mod=1e9+7;
inline ll add(ll a,ll b){
    return  ((a%mod)+(b%mod)+mod)%mod;
}
inline ll mul(ll a,ll b){
    return ((a%mod)*(b%mod)+mod)%mod;
}
void pause(ll id){
    cout << "Waiting " << id << endl;
    cin >> id;
}

const int mxn=1e5+10;


void init(){

    return ;
}


signed main(){
    fast;
    io;
    if(!true){
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    }
    init();
    ll i,j;
    ll k;
    cin >> k ;
    ll a ,b;
    cin >> a >> b;
    if(a%k == 0 || b%k == 0){
        cout << "OK" << endl;
        return 0;
    }
    ll t=(b-a)/k;
    if(t>=1){
        cout << "OK" << endl;
        return 0;
    }
    t=(b/k)-(a/k);
    if(t>=1){
        cout << "OK" << endl;
        return 0;
    }
    cout <<"NG" << endl;
   
    return 0;
}


Measured memory_bytes: 3656