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

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )

typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int N=1e5+10, M=(ll)1e9+1 ;
const int mod = 1e9+7;
vl g[N],vis(N,0);
ll ans=1,root=1,fact[N],k;

ll po(ll a,ll x){
    if(x==0)
        return 1;
    if(x==1)
        return a;
    ll z=po(a,x/2);
    z=(z*z)%mod;
    if(x&1)
        z=(z*a)%mod;
    return z;
}

ll inv(ll x){
    ll ans=po(x,mod-2);
    return ans;
}

ll p(ll n,ll r){
    if(n<r)
        return 0;
    ll ans=(fact[n]*inv(fact[n-r]))%mod;
    return ans;
}
void initial(){
    fact[0]=1;
    for(ll i=1;i<N;i++){
        fact[i]=(fact[i-1]*i)%mod;
    }
}

void dfs(ll u){
    vis[u]=1;
    if(u==1)
        ans=k;
    for(auto &it:g[u]){
        if(vis[it])
            continue;
        dfs(it);
    }
    ll x=g[u].size();
    if(u==root)
        ans=(ans*p(k-1,x))%mod;
    else
        ans=(ans*p(k-2,x-1))%mod;
}

void work(){
    ll n;
    cin >> n >> k;
    for(ll i=1;i<n;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1);
    cout << ans%mod;
    return;
}

int main(){
 ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t,z;
    initial();
//     cin >> t;
//     z=t;
    t=1;
    while(t--){
            // cout << "Case #" << z-t << ": ";
            work();
    }
   return 0;

}


Measured memory_bytes: 9600
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
A = list(map(int, input().split()))

cnt2 = 0
cnt4 = 0

for a in A:
    if a % 4 == 0:
        cnt4 += 1
    elif a % 2 == 0:
        cnt2 += 1

if cnt2 // 2 + cnt4 >= N // 2:
    print("Yes")
else:
    print("No")

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

score = [[0] * (K+1) for y in range(K+1)]
base_hope = 0

for i in range(N):
    x, y, c = input().split()
    x2, y2 = int(x) // K, int(y) // K
    x_coord, y_coord = int(x) % K + 1, int(y) % K + 1
    if ((x2 + y2) % 2 == 0 and c == "W") or ((x2 + y2) % 2 == 1 and c == "B"):
        score[y_coord][x_coord] += 1
        base_hope += 1
    else:
        score[y_coord][x_coord] -= 1

xy = [(x, y) for x in range(K) for y in range(K)]
for x, y in xy:
    score[y+1][x+1] += score[y+1][x] + score[y][x+1] - score[y][x]

max_hope = 0
for x, y in xy:
    hope = base_hope - score[K][x] - score[y][K] + 2 * score[y][x]
    true_hope = hope if hope > N - hope else N - hope
    if true_hope > max_hope:
        max_hope = true_hope

print(max_hope)

Measured memory_bytes: 131708
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
typedef long long ll;

bool isPrime(int n){ 
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0 || n%3==0)
        return false;
    for(int i=5;i*i<=n;i=i+6)
        if(n%i==0 || n%(i+2)==0)
            return false;
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin >> n >> m;
    if(m%n==0){
        cout << m/n;
        return 0;
    }
    if(isPrime(m)){
        cout << 1;
        return 0;
    }
    int x = 2;
    while(m%(n-1+x)!=0)
        x++;
    cout << m/(n-1+x);
}

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

using namespace std;

int main()
{
	int k, x;

	cin >> k;
	cin >> x;

	int min = x - (k - 1);
	int max = x + (k - 1);

	for (int i = min; i <= max; i++)
	{
		cout << i << " ";
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define ELE_MAX 10000

void CountingSort(int);

int A[2000001],B[2000001],n;
int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  CountingSort(ELE_MAX);
  for(i=1;i<=n;i++){
    if(i<n)printf("%d ",B[i]);
    else if(i==n)printf("%d\n",B[i]);
  }
  return 0;
}







void CountingSort(int k)
{
  int i,j,C[2000001];
  for(i=0;i<=k;i++){
    C[i]=0;
  }
  for(j=0;j<n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=n-1;j>=0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}



Measured memory_bytes: 17404
#include<stdio.h>
int main(void)
{
	int a,b,c,d,p,r,f;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&p);
	if(p>c){
		f=p-c;
		r=f*d;
	}
	a*=p;
	b+=r;
	if(b>a){
		printf("%d\n",a);
	}
	else{
		printf("%d\n",b);
	}
	return 0;
}


Measured memory_bytes: 2104
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		
		Console.WriteLine("{0}",Max(Max(s[0]+s[1],s[0]-s[1]),s[0]*s[1]));
	}
}


public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  int N, m;
  cin >> N >> m;
  vi shop(N+1);
  REP(i, m){
    int c, d;
    cin >> c >> d;
    shop[c-1]++;
    shop[d-1]--;
  }
  int res = N + 1;
  int cnt = 0;
  int start = -1;
  REP(i, N){
    if(shop[i] == 0) continue;
    cnt += shop[i];
    if(start == -1) start = i;
    if(cnt == 0) {
      res += (i - start) * 2;
      start = -1;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  int N;
  scanf("%d", &N);
  int a[N];
  set<int> s;
  map<int,int> m;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
    s.insert(a[i]);
    ++m[a[i]];
  }

  if(SZ(s)>3) cout << "No" << endl;
  else if(SZ(s)==3){
    int x,y,z;
    auto pos = s.begin();
    x = *pos; ++pos;
    y = *pos; ++pos;
    z = *pos;

    int ans = (x^y^z);
    if(ans==0 && m[x]==N/3 && N%3==0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else if(SZ(s)==2){
    int x,y;
    auto pos = s.begin();
    x = *pos; ++pos;
    y = *pos;

    int max_num = max(x,y);
    int min_num = min(x,y);
    x = max_num;
    y = min_num;

    if(y==0 && m[x]==N*2/3 && N%3==0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else{
    if(a[0]==0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }


}



Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <assert.h>

using namespace std;

class Edge {
public:
  Edge()
    : src(-1), dest(-1) {}
  Edge(int src_, int dest_)
    : src(src_), dest(dest_) {}
  Edge(const Edge& other)
    : src(other.src), dest(other.dest) {}
  
  void print() {
    cout << "(" << src << ", " << dest << ")" << endl;
  }

  Edge rev() {
    return Edge(dest, src);
  }
  
  bool operator==(const Edge& other) const {
    return src == other.src && dest == other.dest;
  }
  
  bool operator<(const Edge& other) const {
    return (dest < other.dest) || (dest == other.dest && src < other.src);
  }

  int src;
  int dest;
};

class Graph {
public:
  Graph(int n)
    : num_of_nodes(n) {
  }

  void add_edge(int src, int dest) {
    edges.insert(Edge(src, dest));
  }
  
  int num_of_nodes;
  set<Edge> edges;

  int num_of_one_stroke();
  void add_targets(set<int>& reached, int node, queue<tuple<set<int>, int>>& targets) {
    for (Edge e : edges) {
      if (e.src == node) {
	set<int> new_reached = reached;
	new_reached.insert(node);
	targets.push(make_tuple(new_reached, e.dest));
      } 
      if (e.dest == node) {
	set<int> new_reached = reached;
	new_reached.insert(node);
	targets.push(make_tuple(new_reached, e.src));
      }
    }
  }
};

int Graph::num_of_one_stroke()
{
  int n = 0;
  queue<tuple<set<int>, int>> targets;
  targets.push(make_tuple(set<int>(), 0));
  while (!targets.empty()) {
    auto pair = targets.front(); 
    set<int> reached = get<0>(pair);
    int node = get<1>(pair);
    targets.pop();
    if (reached.find(node) != reached.end()) {
      continue;
    }
    if (reached.size() + 1 == num_of_nodes) {
      n++;
    } else {
      add_targets(reached, node, targets);
    }
  }
  return n;
}

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

  Graph g(n);
  for (int i = 0; i < m; i++) {
    int src, dest;
    cin >> src >> dest;
    g.add_edge(src - 1, dest - 1);
  }

  cout << g.num_of_one_stroke() << endl;
  
  return 0;
}


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

#define INF (1 << 29)

int main(){
	int n;
	double input;
	double min_diff = INF;
	double ans = 0;
	vector<double> a;
	
	scanf("%d",&n);
	for(int i = 0;i < n;++i){
		scanf("%lf",&input);
		a.push_back(input);
	}
	
	sort(a.begin(), a.end());
	
	for(int i = 1;i < n - 2;++i){
		min_diff = min(min_diff, a[i] - a[i - 1]);
	}
	
	ans = max(ans, (a[n - 1] + a[n - 2]) / min_diff);
	
	ans = max(ans, (a[n - 1] + a[n - 3]) / (a[n - 2] - a[n - 4]));
	ans = max(ans, (a[n - 3] + a[n - 4]) / (a[n - 1] - a[n - 2]));
	
	printf("%.6lf\n", ans);
	
	return 0;
}



Measured memory_bytes: 3268
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
l = [pow(10,i) for i in range(1,7)]

if N in l:
    print(10)
else:
    num = 0
    for i in str(N):
        num += int(i)
    print(num)

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

using namespace std;

int main(int argc, char const *argv[])
{
    int k;
    string s;
    cin >> k;
    cin >> s;

    if (s.size() <= k)
    {
        cout << s << endl;
    }
    else
    {
        cout << s.substr(0, k) << "..." << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
r, g, b, n = map(int,input().split())
ans = 0

for i in range(n+1):
    x = i*r
    if x > n:
        break
    for j in range(n+1):
        y = j*g
        z = n-x-y
        if x+y > n:
            break
        if z >= 0 and z%b == 0:
            ans += 1

print(ans)


Measured memory_bytes: 9100
#include <iostream>
#include <map>
using namespace std;
map < long long, long long > cnt;
long long n, a[(1<<20)], cSum, ans;
int main () {
    cnt[0] = 1;
    cin >> n;
    for ( int i = 0 ; i < n ; i ++ ) {
        cin >> a[i];
        long long nSum = cSum + a[i];
        ans += cnt[ nSum ];
        cSum += a[i];
        cnt[ cSum ] ++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 14336
import java.util.Arrays;
import java.util.Scanner;


public class Main {
    static Scanner s = new Scanner(System.in);

    static class Point {
        int x=0;
        int y=0;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public static void main(String[] args) {
        while (true) {
            int n = s.nextInt();
            if(n==0) break;

            int m = s.nextInt();

            int count = 0;
            Point[] p = new Point[m];

            for (int j = 0; j < m; j++) {
                int x = s.nextInt();
                int y = s.nextInt();

                p[j] = new Point(x,y);
            }
            for (int i = 0; i < n; i++) {
                int m2 = s.nextInt();
                Point[] p2 = new Point[m2];

                for (int j = 0; j < m2; j++) {
                    int x = s.nextInt();
                    int y = s.nextInt();

                    p2[j]=new Point(x,y);
                }

                if (check(p, p2)) System.out.println(i+1);
                else {
                    reverse(p2);
                    if (check(p, p2)) System.out.println(i+1);
                }
            }
            System.out.println("+++++");
        }
    }
    public static boolean check(Point[] p, Point[] p2){
        int difx,dify;
        boolean flag;

        if(p.length!=p2.length) return false;

        for(int i=1;i<p2.length;i++){
            p[i].x-=p[0].x;
            p[i].y-=p[0].y;
            p2[i].x-=p2[0].x;
            p2[i].y-=p2[0].y;
        }
        p[0].x=0;
        p[0].y=0;
        p2[0].x=0;
        p2[0].y=0;

        flag=turnCheck(p,p2,0);

        return flag;
    }

    public static boolean turnCheck(Point[] p, Point[] p2,int num){
        boolean flag;
        if(num ==4) return false;

        if(p[1].x==p2[1].x && p[1].y==p2[1].y){
            for(int i=2;i<p.length;i++){
                if(!(p[i].x==p2[i].x && p[i].y==p2[i].y)){
                    return false;
                }
            }
            return true;
        } else {
            for (int i=1;i<p2.length;i++){
                int tempx=p2[i].x;
                int tempy=p2[i].y;
                p2[i].x=-tempy;
                p2[i].y=tempx;
            }
            flag=turnCheck(p,p2,num+1);
        }
        return flag;
    }

    public static final void reverse(Point[] arr) {
        final int len = arr.length;
        Point tmp;
        for (int i = 0; i < len / 2; i++) {
            tmp = arr[i];
            arr[i] = arr[len - 1 - i];
            arr[len - 1 - i] = tmp;
        }
    }
}

Measured memory_bytes: 29108
// ---------- begin chmin, chmax ----------
trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------

use proconio::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        a: [[u16; 4]; n],
    }
    let mut a: Vec<_> = a.into_iter().map(|a| [a[0], a[1], a[2], a[3]]).collect();
    let mut map = std::collections::BTreeMap::new();
    for a in a.iter_mut() {
        let mut x = *a;
        for _ in 0..4 {
            a.chmin(x.clone());
            x.rotate_left(1);
        }
        *map.entry(a.clone()).or_insert(0u64) += 1;
    }
    let mut ans = 0;
    for (i, f) in a.iter().enumerate() {
        *map.get_mut(f).unwrap() -= 1;
        for down in a.iter().skip(i + 1) {
            *map.get_mut(down).unwrap() -= 1;
            let mut t = [down[1], down[0], down[3], down[2]];
            for _ in 0..4 {
                let mut memo = std::collections::BTreeMap::new();
                let x = [f[3], f[2], f[1], f[0], f[3]];
                let y = [t[3], t[2], t[1], t[0], t[3]];
                for (x, y) in x.windows(2).zip(y.windows(2)) {
                    let mut p = [x[0], x[1], y[1], y[0]];
                    let mut q = p.clone();
                    for _ in 0..4 {
                        p.chmin(q.clone());
                        q.rotate_left(1);
                    }
                    *memo.entry(p).or_insert(0) += 1;
                }
                let mut val = 1;
                for (p, c) in memo {
                    let mut q = p.clone();
                    let mut v = 0;
                    for _ in 0..4 {
                        if p == q {
                            v += 1;
                        }
                        q.rotate_left(1);
                    }
                    let a = map.get(&p).cloned().unwrap_or(0);
                    for i in 0..c {
                        val *= (a - i) * v;
                    }
                }
                ans += val;
                t.rotate_left(1);
            }
            *map.get_mut(down).unwrap() += 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2228
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False

def main():
  A = []
  for _ in range(3):
    A+=ints()
  n = aint()
  for _ in range(n):
    num = aint()
    for i in range(9):
      if A[i]==num: A[i]=0
  b = sum(A[:3])*sum(A[3:6])*sum(A[6:])*(A[0]+A[3]+A[6])*(A[1]+A[4]+A[7])*(A[2]+A[5]+A[8])*(A[0]+A[4]+A[8])*(A[2]+A[4]+A[6])
  Yes(b==0)
    
if __name__ == '__main__':
  main()

Measured memory_bytes: 3316
r, c = gets.chomp.split.map(&:to_i)
sheet = []
last_culumn = Array.new(c, 0)
last_sum = 0
r.times do |y|
    line = gets.chomp.split.map(&:to_i)
    last_sum += line.sum
    line << line.sum
    sheet << line
    last_culumn = last_culumn.zip(line).map{ |a, b| a + b }
end
last_culumn << last_sum
sheet << last_culumn

sheet.each { |s| puts s.join(" ")}


Measured memory_bytes: 7104
#include <bits/stdc++.h>
using namespace std;
using s64 = signed long long;
using u64 = unsigned long long;
using f128 = long double;

int main()
{
    s64 x, k, d;
    cin >> x >> k >> d;

    if(x < 0)
    {
        x *= -1;
    }

    s64 stepCount = x / d;
    if(stepCount >= k)
    {
        cout << abs(x - d * k) << endl;
        return 0;
    }

    s64 minX = x - d * stepCount;
    s64 leftStep = k - stepCount;
    if(leftStep % 2 == 0)
    {
        cout << abs(minX) << endl;
    }
    else
    {
        cout << abs(minX - d) << endl;
    }

    return 0;
}


Measured memory_bytes: 3432
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

R, C, N = reads()

def edge(x, y):
  return x == 0 or x == R or y == 0 or y == C

def flat(x, y):
  assert edge(x, y)
  if y == 0:
    return x
  elif x == R:
    return R + y
  elif y == C:
    return R + C + (R - x)
  else:
    assert x == 0
    return 2 * R + C + (C - y)

ps = []
for i in range(N):
  x1, y1, x2, y2 = reads()
  if edge(x1, y1) and edge(x2, y2):
    ps.append((flat(x1, y1), i))
    ps.append((flat(x2, y2), i))
ps.sort()

stack = []
for _, i in ps:
  if len(stack) > 0 and stack[-1] == i:
    stack.pop()
  else:
    stack.append(i)

print("YES" if len(stack) == 0 else "NO")

Measured memory_bytes: 85080
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vec;
vec calc(vec a,vec b){
  int n=a.size();
  vec res(n,0);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      res[(i+j)%n]+=a[i]*b[j];
      res[(i+j)%n]%=MOD;
    }
  }
  return res;
}
signed main(){
  int n,m,k;
  cin>>n>>m>>k;
  int p[m];
  for(int i=0;i<m;i++) cin>>p[i];
  vec t(n,0);
  t[0]=1;
  for(int i=0;i<m;i++) t[p[i]%n]++;
  vec ans(n,0);ans[0]=1;
  while(k){
    if(k&1) ans=calc(ans,t);
    t=calc(t,t);
    k>>=1;
  }
  for(int i=0;i<n;i++) cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef  long long int ll;
using namespace std;
const int M=1e9+7;
const int N=1e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
//ll ans[N];
int main()
{
    ll n;cin>>n;
    ll a[n+1][3];
    a[0][0]=0,a[0][1]=0,a[0][2]=0;
    for(ll i=1;i<=n;++i)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
        a[i][0]+=max(a[i-1][1],a[i-1][2]);
         a[i][1]+=max(a[i-1][0],a[i-1][2]);
          a[i][2]+=max(a[i-1][1],a[i-1][0]);
    }
    ll ans=max(a[n][0],max(a[n][1],a[n][2]));
    cout<<ans;  
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    int n;
    ll sum = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if (i % 3 != 0 && i % 5 != 0)
            sum += i;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3624
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)1e5+100;

int main(void) {
   ll A,B;
   cin>>A>>B;
   if ((A-B)%2!=0) cout<<"IMPOSSIBLE"<<endl;
   else cout<<(A+B)/2<<endl;



   return 0;
}

Measured memory_bytes: 256
// AOJ 0159
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(void)
{
	int n;
	while (cin >> n, n){
		vector < pair <double, int> > d;
		double h, w;
		int id;
		for (int i = 0; i < n; i++){
			cin >> id >> h >> w;
			h /= 100.0;
			double bmi = w / (h * h);
			d.push_back(make_pair(abs(bmi - 22.0), id));
		}
		sort(d.begin(), d.end());
		// for (int i = 0; i < n; i++){
		// 	cout << d[i].first << " " << d[i].second << endl;
		// }
		cout << d[0].second << endl;
	}

	return 0;
}

Measured memory_bytes: 1268
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
const int MOD = 1000000007;
using namespace std;

int main(){
    int N;
	cin >> N;
    int A;
    int min=1000000000, max=1;
    for (int i = 0; i < N; i++){
        cin >> A;
        if (A >= max){
            max = A;
        }
        if (A <= min){
            min = A;
        }
    }

    cout << max-min << endl;
}

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

static const int N = 1000;

int lcs(string X, string Y) {
    //DP memotable: c
    int c[N+1][N+1];
    int xSize = X.size();
    int ySize = Y.size();
    int maxl = 0;
    //first char will be empty because of dp table
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i <= xSize; i++) c[i][0] = 0;
    for (int j = 0; j <= ySize; j++) c[0][j] = 0;

    for (int i = 1; i <= xSize; i++) {
        for (int j = 1; j <= ySize; j++) {
            if (X[i] == Y[j]) c[i][j] = c[i-1][j-1]+1;
            else c[i][j] = max(c[i-1][j], c[i][j-1]);
            maxl = max(maxl, c[i][j]);
        }
    }
    /*
    for (int i = 1; i <= xSize; i++) {
        for (int j = 1; j <= ySize; j++) {
            cout << c[i][j] << " ";
        }
        cout << endl;
    }
    */
    return maxl;
}

int main()
{
    int n; cin >> n;
    //string s1 = "abcbdab";
    //string s2 = "bdcaba";
    string s1, s2;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}



Measured memory_bytes: 7064
#include<iostream>
#include<cctype>
using namespace std;
int main(){
  char ch,c;
  int counter[26]={0},num;
  while(cin >>ch){
    c=tolower(ch);
  num =c-'a';  
  if(isalnum(ch))counter[num]++;}

  for(int i=0;i<26;i++) cout<<(char)('a'+i)<<" : "<<counter[i]<<endl;
  return 0;
}
    

Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
  int n;
  ll a[100010],sum=0;
  cin >> n;
  FOR(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  ll cnt=0;
  ll kari[100010];
  kari[0]=0;
  for(int i=1;i<n;i++){
    if(a[(cnt+1)%n]>a[(cnt+2)%n]){
        kari[(cnt+2)%n]=kari[cnt%n]-(a[(cnt+1)%n]-a[(cnt+2)%n])*2;
      }else{
        kari[(cnt+2)%n]=kari[cnt%n]+(a[(cnt+2)%n]-a[(cnt+1)%n])*2;
      }
      cnt+=2;
  }
  ll num=0;
  FOR(i,n){
    num+=kari[i];
  }
  cout << kari[n-1]+(sum-num)/n << endl;
  FOR(i,n-1){
    cout << kari[i]+(sum-num)/n << endl;
  }
  
}


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

using namespace std;

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

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

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int mod=1e9+7;
int32_t main(){
    int n,k,ans=1,pos=0,neg=0,z=0,t,ok=1,s=1,e,i;
    cin>>n>>k;
    int a[n+1];
    vector<int>vpos,vneg;
    for(i=1;i<=n;i++){cin>>a[i];
        if(a[i]>0){pos++;}
        if(a[i]<0)neg++;
        if(a[i]==0)z++;
    }
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    if(n==k){
        for(i=1;i<=n;i++){ans*=a[i];ans%=mod;}
        ans=(ans+mod)%mod;
        cout<<ans;return 0;
    }
    if(!neg){
        for(i=1;i<=k;i++){ans*=a[i];ans%=mod;}
        cout<<ans;
        return 0;
    }
    t=min(k,neg);
    if(t%2)t--;
    if(t+pos<k)ok=0;
    if(!ok&&z){cout<<"0";return 0;}
if(!ok){
    for(i=1;i<=k;i++){ans*=a[i];ans%=mod;}
    ans=(ans+mod)%mod;
    cout<<ans;return 0;
}s=1;
 if(k%2){
     ans=a[1];
     k--;
     s=2;
 } e=n;
 while(k){
     if(a[s]*a[s+1]>a[e]*a[e-1]){
         ans*=a[s];
         ans%=mod;
         ans*=a[s+1];ans%=mod;
         s+=2;
     }else{
         ans*=a[e];
         ans%=mod;
         ans*=a[e-1];
         ans%=mod;
         ans=(ans+mod)%mod;
         e-=2;
     }
     k-=2;
 }
 cout<<ans;
    return 0;
}

Measured memory_bytes: 5172
h,w=gets.chomp.split(" ").map(&:to_i)
maths = []
h.times do
  tempArray = []
  tempArray = gets.chomp.split("")
  maths << tempArray if tempArray.uniq != ["."]
end
sliceIndexes = []
w.times do |wIndex|
  tempArray = []
  maths.length.times do |hIndex|
    tempArray << maths[hIndex][wIndex]
  end
  sliceIndexes << wIndex if tempArray.uniq == ["."]
end
sliceIndexes.sort.reverse.each do |val|
  maths.length.times do |hIndex|
    maths[hIndex].slice!(val)
  end
end
maths.each do |val|
  puts val.join.to_s
end

Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const ll mod = 1e9 + 7;

int modPow(ll a, ll n, ll p) {
    if (n == 1) return a % p;
    if (n % 2 == 1) return a * modPow(a, n - 1, p) % p;
    ll t = modPow(a, n / 2, p);
    return t * t % p;
}



int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll x = modPow(2, n, mod);
    ll yf = 1;
    for (ll i = 1; i <= a; ++i) {
        yf *= i;
        yf %= mod;
    }
    yf = modPow(yf, mod - 2, mod) % mod;
    ll yg = 1;
    for (ll i = n; i >= n - a + 1; --i) {
        yg *= i;
        yg %= mod;
    }
    ll zf = 1;
    for (ll i = 1; i <= b; ++i) {
        zf *= i;
        zf %= mod;
    }
    zf = modPow(zf, mod - 2, mod) % mod;
    ll zg = 1;
    for (ll i = n; i >= n - b + 1; --i) {
        zg *= i;
        zg %= mod;
    }
    ll y = yf * yg % mod;
    ll z = zf * zg % mod;
    ll ans = (x - y - z - 1 + 10 * mod) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a[10];
    int i,j;
    int tmp;
    
    for(i=0; i<10; i++){
        scanf("%d",&a[i]);
    }
    
    for(i=0; i<9; i++){
        for(j=9; j>i; j--){
            if(a[j-1] > a[j]){
                tmp = a[j-1];
                a[j-1] = a[j];
                a[j] = tmp;
            }
        }
    }
    
    for(i=9; i>6; i--){
        printf("%d\n",a[i]);
    }
    
    return 0;
}

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

int n, k, h[110000], cost[110000];

int main() {
	cin >> n >> k;
    for (int i=1; i<=n; i++) {
      cin >> h[i];
      cost[i] = 2e9;
    }
    cost[1] = 0;
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=k; j++) {
      	if (i+j<=n) {
          cost[i+j] = min(cost[i+j], cost[i]+abs(h[i+j]-h[i]));
        }
      }
    }
    cout << cost[n] << "\n";
    return 0;
}

Measured memory_bytes: 1024
function Main(input) {
  input = input.split(' ');
  num = Number(input[0]);
  lastNum = Number(input[1]);
  count = 0;
  while(num <= lastNum){
    pal = String(num);
    if (pal[0] === pal[4] && pal[1] === pal[3]) {
      count++;
    }
    num++;
  }
  console.log(count);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 10572
import java.util.Scanner

fun main(args: Array<String>){
	val sc = Scanner(System.`in`)
	val N = Integer.parseInt(sc.nextLine())
	val S = sc.nextLine().split(" ")

	val A = IntArray(N)
	for(i in 0..N-1) A[i]=Integer.parseInt(S[i])

	//val m = LLCM(A) - 1
	var count = -N

	for(i in 0..N-1) count += A[i]

	println(count)

}

Measured memory_bytes: 38576
#define ll long long int
#include <bits/stdc++.h>
//#include <fstream>
using namespace std;
 
#define         ff               first
#define         ss               second
#define         mp               make_pair
#define         pb               push_back
#define         pf               push_front
#define         vi               vector<ll>
#define         pii              pair<ll,ll>
#define         qi               queue<ll>
#define         mem(a,b)         memset(a,b,sizeof(a))
#define         print(a)         cout<<a<<'\n'
#define         sorted(arr)      sort(arr.begin(),arr.end())
#define         gcd(a,b)         gcd((a),(b))
#define         lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define         all(v)           v.begin(),v.end()
#define         read(a)          scanf("%d", &a)
#define         f(a,n)           for(ll i=a;i<n;i++)
#define         in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define         debug(a)         cerr<<a<<" ";
#define         debug1(a)        cerr<<a<<'\n'
 
/*typedef tree<int, null_type, less<int>, rb_tree_tag , tree_order_statistics_node_update> Set;*/
 
 
const unsigned ll mod = 1e9 + 7 ;
const ll inf = (ll)1e18 + 2;
const ll N = (ll)1e6 + 2;
//
//template<typename... T>
//void write(T&... args)
//{
//    ((cout << args << ' '), ...);
//}
//ll power ( ll x , ll y)
//{
//    ll res = 1;
//    while (y > 0)
//    {
//        if (y & 1)
//            res = (res * x) ;
//        y = y >> 1;
//        x = (x * x) ;
//    }
//    return res  ;
//}
//
//struct node{
//    ll x , y , z;
//};
//map<pair<ll, ll>,ll> c;
//vector<set<ll>> tree;
//vector<ll> ar ;
//set<ll> s;
//ll get(ll x)
//{
//    if(x == ar[x])
//        return x;
//    return ar[x] = get(ar[x]);
//}
//void merge(ll a ,ll b)
//{
//    a = get(a);
//    b = get(b);
//    if(a == b)
//    {
//        return ;
//    }
//    ar[b] = ar[a];
// }
//
//ll sev[100006];
//vector<ll> pri;
//void seive()
//{
//    for(ll i = 2 ; i < 100006 ; i ++)
//    {
//        if(!sev[i])
//        {
//            for(ll j = i ; j < 100006 ; j += i)
//            {
//                if(!sev[j])
//                    sev[j] = i;
//            }
//        }
//        if(sev[i] == i)
//            pri.pb(i);
//    }
//}
void solve()
{
    string s1 , s2;
    cin >> s1;
    for(ll i = 0; i < s1.size() ; i ++)
        cout << 'x';
    cout << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t ;
    t = 1;
    //cin >> t;
    //seive();
    while(t --)
    {
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
 


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j,k,l,m,d[100010],b[100010]={};
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  for(i=0;i<(4<n?4:n);i++){
    for(j=0;i+j<n;j++){
      for(k=m=0;k<=i;k++)m=m*10+d[j+k];//printf("%d\n",m);
      b[m]=1;
    }
  }
  for(i=0;b[i];i++);
  printf("%d\n",i);
  return 0;
}

Measured memory_bytes: 1008
n,d = map(int,input().split())
pnt = [list(map(int,input().split())) for _ in range(n)]

def dst(i, j):
    a = pnt[i]
    b = pnt[j]
    ret = 0
    for p, q in zip(a, b):
        ret += (p - q) ** 2
    r = int(ret ** (0.5))
    if r ** 2 == ret:
        return True
    else:
        return False

ret = 0
for i in range(n):
    for j in range(i + 1, n):
        tmp = dst(i, j)
        if tmp:
            ret += 1
print(ret)

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
 
 
int main() {
	int n;
	ull a[200001];
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin>>a[i];
	}
 
	ull ans = 0;
	ull x=0;
	for (int i = 0,j=0;j < n;) {
		while(((x+a[i])==(x^a[i]))&&(i<n)){
			x += a[i];
			
			i++;
		}
		ans += (i - j);
		x -= a[j];
		
		j++;
	
	}
 
	cout << ans << endl;
 
 
 
	return 0;
}

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

int N, M;
const int MAX_NM = 1.0e5 + 100;
int p[MAX_NM];

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    cin >> N >> M;
    vector<pair<int, int> > p;
    for (int i = 0; i < N; i++) {
        int p_in;
        cin >> p_in;
        p.push_back(make_pair(i, p_in - 1));
    }

    UnionFind tree(N);

    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (tree.same(p[i].first, p[i].second)) {
            ans++;
        }
    }
    
    cout << ans << endl;

    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N, K;
    cin >> N >> K;
    
    vector<int> H(N);
    rep(i, N) cin >> H[i];

    sort(H.begin(), H.end(), greater<int>());

    ll ans = 0;
    rep(i, N) {
        if (i < K) continue;
        ans += H[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define NR 10000
#define E 500000

typedef struct point {
  int x, ver, length;
} GVE;

int main(){
  GVE W[E];
  int n, i, j, g, ci, size = 0;
  int d[NR];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &ci);
    scanf("%d", &g);

    for(j = 1; j <= g; j++){
      W[size].x = ci;
      scanf("%d %d", &W[size].ver, &W[size].length);
      size++;
    }
  }

  for(i = 1; i < n; i++){
    d[i]=INT_MAX;
  }
  j = 1;
  while(j){
    j = 0;
    for(i = 0; i < size; i++) {
      if(d[W[i].x] !=INT_MAX && d[W[i].x]+W[i].length < d[W[i].ver]) {
        d[W[i].ver] = d[W[i].x]+W[i].length;
        j++;
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("%d %d\n", i, d[i]);
  }
  return 0;
}

Measured memory_bytes: 6464
import sys

N = int(input())
h = list(map(int, input().split()))
cnt = 0
start = 0
end = 0
if sum(h) == 0:
    print(0)
    sys.exit()

while True:
    for i in range(N):
        if h[i] != 0:
            start = i
            break

    end = N
    for i in range(start + 1, N):
        if h[i] == 0:
            end = i
            break

    for i in range(start, end):
        if h[i] != 0:
            h[i] = h[i] - 1

    cnt += 1
    start = 0
    end = 0
    if sum(h) == 0:
        break

print(cnt)


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

long long a;

int main () {
    while (scanf("%lld", &a) == 1) {
        map<long long, int> m;
        for (int d = 2; 1ll * d * d <= a && a != 1; d++) {
            while (a % d == 0) {
                a /= d;
                m[d]++;
            }
        }
        if (a != 1) m[a]++;

        int res = 0;
        for (auto &p : m) {
            int nd = p.second;
            for (int i = 1; i <= nd; i++) {
                nd -= i;
                res++;    
            }
        }
        printf("%d\n", res);
    }
}



Measured memory_bytes: 3788
from collections import Counter

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    akeys = a.keys()
    mx = max(akeys)
    cnt = 0
    for i in akeys:
        c = a[i]
        if i+1 in akeys:
            c += a[i+1]
        if i+2 in akeys:
            c += a[i+2]
        cnt = max(cnt, c)
    print(cnt)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 16612
#include<iostream>
using namespace std;
int main()
{
  int n,y;
  cin>>n>>y;
  int mark=0;
  int a,b,c;

  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=n;j++)
    {

        if(10000*i+5000*j+1000*(n-i-j)==y && n-i-j>=0)
        {
          mark=1;
          a=i;
          b=j;
          c=n-i-j;
        }

    }
  }

  if(mark==1) cout<<a<<" "<<b<<" "<<c<<endl;
  else    cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200 + 7, maxm = 63;
int Td, n;
long long A[maxm], B[maxm];
long long a[maxn];
char s[maxn];

void insert(long long *t, long long x) {
	for (int i = 62; ~i; --i) if(x & (1ll << (long long)i)) {
		if(t[i]) x ^= t[i];
		else {
			t[i] = x;
			break;
		}
	}
	for (int i = 1; i <= 62; ++i) if(t[i]) {
		for (int j = i - 1; ~j; --j) if(t[i] & (1ll << (long long)j)) 
			t[i] ^= t[j];
	} 
}

bool check() {
	for (int i = 62; ~i; --i) {
		long long x = B[i];
		if(x == 0) continue;
		for (int j = i; ~j; --j) if(x & (1ll << (long long)j)) {
			if(!A[j]) return 0;
			x ^= A[j];
		}
	}
	return 1;
}

int main() {
	scanf("%d", &Td);
	while(Td--) {
		scanf("%d", &n);
		for (int i = 0; i <= 62; ++i) A[i] = B[i] = 0;
		for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
		scanf("%s", s + 1);
		int fl = 1;
		for (int i = n; i >= 1; --i) {
			if(s[i] == '0') insert(A, a[i]);
			else {
				insert(B, a[i]);
				if(!check()) {
					printf("1\n");
					fl = 0;
					break;
				}
			}
		}
		if(fl) printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 3688
const Main = (input) => {
  const ar = input[1].split(' ');
  var mx = 1;
  var mn = Math.pow(10, 9);
  for (var v of ar) {
    mx = parseInt(v) > mx ? parseInt(v) : mx;
    mn = parseInt(v) < mn ? parseInt(v) : mn;
  }
  console.log(mx - mn);
}

// 標準入力を受け取るおまじない
Main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'));


Measured memory_bytes: 7500
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
//素数判定
bool prime(ll n) {
	if (n == 1)return false;
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return true;
}
ll a[114514], b[114514];
signed main() {
	ll n, m;
	cin >> n >> m;
	ll memo1 = 0, memo2 = 0;
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];
	for (int i = 0; i < n; i++) {
		if ((n - 1 - 2 * i) >= 0)memo1 += (a[n - 1 - i] - a[i])*(n - 1 - 2 * i);
		memo1 %= 1000000007;
	}
	for (int i = 0; i < m; i++) {
		if ((m - 1 - 2 * i) >= 0)memo2 += (b[m - 1 - i] - b[i])*(m - 1 - 2 * i);
		memo2 %= 1000000007;
	}
	cout << memo1 * memo2 % 1000000007 << endl;
	ggr
}


Measured memory_bytes: 1792
def bubblesort a,n
  for i in 0...n
    j = n-1
    while j > i
      if a[j][1].ord < a[j-1][1].ord
        t = a[j]
        a[j] = a[j-1]
        a[j-1] = t
      end
      j -= 1
    end
  end
  a
end

def selectionsort a,n
  for i in 0...n
    min = i
    for j in i...n
      min = j if a[j][1].ord < a[min][1].ord
    end
    if min != i
      t = a[i]
      a[i] = a[min]
      a[min] = t
    end
  end
  a
end

def showarray a,n
  for i in 0...n
    print " " unless i == 0
    print a[i]
  end
  print "\n"
end

n = gets.to_i
a = gets.split
b = bubblesort a.clone,n
c = selectionsort a.clone,n

showarray b,n
puts "Stable"

showarray c,n
if b == c
  puts "Stable"
else
  puts "Not stable"
end

Measured memory_bytes: 6120
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main (){
    ll n,k,count=0,ans=0;
    cin >> n >> k;
    ll a[n];
    ll c=((k*(k-1))/2)%MOD;
    for (ll i=0;i<n;i++)cin >> a[i];
    for (ll i=0;i<n;i++){
        ll x=a[i];
        ll count2=0;
        for (ll j=i+1;j<n;j++){
            ll y=a[j];
            if (x>y)count++;
        }
        for (ll j=0;j<n;j++){
            ll y=a[j];
            if (x>y)count2++;
        }
        ans+=count2*c;
        ans%=MOD;
    }
    ans+=count*k;
    ans%=MOD;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888