akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define fi first
#define se second
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int N;
cin >> N;

vl A(N);
rep(i,N) cin >> A[i];

map<ll, ll> p,q;

rep(i,N) {
    p[A[i] + i]++;
    q[i - A[i]]++;
}
ll ans = 0;
for(auto x : p) {
    ans += x.se * q[x.fi];
}
cout << ans << endl;
return 0;
}

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

int main(){
  string S;
  cin >> S;
  if(S.size()%2!=0){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0;i<S.size()-1;i+=2){
    if(S.substr(i,2)!="hi"){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
def solve():
    
    n = int(input())
    
    divisors = [0 for _ in range(n+1)]
    
    for i in range(1, n+1):
        for j in range(i, n+1, i):
            divisors[j] += 1
    #print(divisors)
    
    ans = 0
    for k in range(n+1):
        ans += (k * divisors[k])
    
    print(ans)

solve()


Measured memory_bytes: 224848
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[][] info = new int[N][2];

        for (int i = 0; i < N; i++) {
            info[i][0] = sc.nextInt();
            info[i][1] = sc.nextInt();
        }

        int z = 0;
        for (int i = 0; i < N; i++) {

            if (info[i][0] == info[i][1]) {
                z++;
            } else {
                z = 0;
            }

            if (z == 3) {
                System.out.println("Yes");
                return;

            }
        }
        System.out.println("No");
    }
}

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

#define die return cout << "Yes", 0

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

    vt<int> a(9);
    for (int &i : a) cin >> i;
    int n;
    cin >> n;
    while (n--) {
        int x;
        cin >> x;
        for (int i = 0; i < 9; i++) {
            if (a[i] == x) a[i] = 0;
        }
    }

    for (int i = 0; i < 3; i++) {
        if (!a[i * 3] && !a[i * 3 + 1] && !a[i * 3 + 2]) die;
        if (!a[i] && !a[i + 3] && !a[i + 6]) die;
    }
    if (!a[0] && !a[4] && !a[8]) die;
    if (!a[2] && !a[4] && !a[6]) die;

    cout << "No";
}


Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n ; cin >> n ;
	ll a,b,sum=0 ;
	cin >> a >> b ;
	for(int i=2;i<n;i++){
		ll d ; cin >> d ;
		sum ^= d ;
	}
	if(sum>a+b){
		//cout << "a\n" ;
		cout << -1 << endl ;
		return 0 ;
	}
	ll num = 0 ;
	ll sub = (a+b-sum) ;
	if(sub&1){
		//cout << "b\n" ;
		cout << -1 << endl ;
		return 0 ;
	}
	sub /= 2 ;
	for(int i=62;i>=0;i--){
		if(sum>>i&1) continue ;
		if(sub>=(1LL<<i)){
			num |= (1LL<<i) ;
			sub -= (1LL<<i) ;
		}
	}
	if(sub!=0){
		//cout << "c\n" ;
		cout << -1 << endl ;
		//cout << sub << endl ;
		return 0 ;
	}
	for(int i=62;i>=0;i--){
		if(sum>>i&1){
			if(num+(1LL<<i)<=a){
				num |= (1LL<<i) ;
			}
		}
	}
	if(num==0||num>a){
		//cout << "d\n" ;
		cout << -1 << endl ;
		return 0 ;
	}
	cout << a-num << endl ;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> X(N);

    int min = 101;
    int max = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> X[i];
        if (X[i] < min)
        {
            min = X[i];
        }
        if (max < X[i])
        {
            max = X[i];
        }
    }

    long ans = LONG_MAX;
    for (int i = min; i <= max; i++)
    {
        long temp = 0;
        for (int x : X)
        {
            temp += (i - x) * (i - x);
        }

        if (temp < ans)
        {
            ans = temp;
        }
    }

    cout << ans << endl;
}


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

using namespace std;

const int maxn=50001;

int prime[maxn],cnt,res;
bool isprime[maxn];

void maketable()
{
    int base=(int)sqrt((double)maxn);
    isprime[0]=isprime[1]=1;
    for(int i=2;i<maxn;i++){//此处i<maxn与以前的不同
        if(!isprime[i]){
            prime[cnt++]=i;
            for(int j=i+i;j<maxn;j+=i){
                isprime[j]=1;
            }
        }
    }
}

void solve(int n)
{
    int k=(int)sqrt((double)n);
    for(int i=0;prime[i]<=k;i++){
        if(n%prime[i]==0){
            return ;
        }
    }
    res++;
}

int main()
{
    maketable();
    int n,s;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&s);
        solve(s);
    }
    printf("%d\n",res);
    return 0;
}



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

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

  int n;
  cin >> n;

  vector<int> a(n * 3);
  for (int i = 0; i < n * 3; i++) {
    cin >> a[i];
  }

  sort(a.rbegin(), a.rend());

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += a[i * 2 - 1];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1408
X=int(input())
if X<600:
    print(8)
elif X<800:
    print(7)
elif X<1000:
    print(6)
elif X<1200:
    print(5)
elif X<1400:
    print(4)
elif X<1600:
    print(3)
elif X<1800:
    print(2)
elif X<2000:
    print(1)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                           //     #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<pa,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;
                                        
                                  class pas{
                                    	public:
                                    	int x,y;
                                    	pas(int x=0,int y=0):x(x),y(y) {}
                                    	pas operator + (pas p) {return pas(x+p.x,y+p.y);}
                                    	pas operator - (pas p) {return pas(x-p.x,y-p.y);}
                                    	pas operator * (int a) {return pas(x*a,y*a);}
                                    	pas operator / (int a) {return pas(x/a,y/a);}
                                    //	double absv() {return sqrt(norm());}
                                    	int norm() {return x*x+y*y;}
                                    	bool operator < (const pas &p) const{
                                    		return x != p.x ? x<p.x: y<p.y;
                                    	}
                                    	bool operator == (const pas &p) const{
                                    		return x==p.x && y==p.y;
                                    	}
                                    };
int a[60];
           signed main(){
        
          char a,b;
           	cin>>a>>b;
           	if(a<b) cout<<"<"<<endl;
           	if(a>b) cout<<">"<<endl;
           	if(a==b) cout<<"="<<endl;
           	
           	return 0;
           	
           	
           }
             

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

int main()
{
   int n, m;
   cin >> n >> m;
   int a[m], b[m];
   ll c[m], dist[n];
   rep(i,m)
   {
      cin >> a[i] >> b[i] >> c[i];
      c[i] = - c[i];
   }
   rep(i,n) dist[i] = INF;
   dist[0] = 0;
   for(int i = 0; i < n-1; i++)
   {
      for(int j =0; j < m;j++)
      {
         if(dist[a[j]-1] == INF) continue;
         //printf("d[b]: %ld  d[a]: %ld c: %ld\n", dist[b[j] -1], dist[a[j] -1], c[j]);
         if (dist[b[j] - 1] > dist[a[j] - 1] + c[j]) 
         {
            dist[b[j] - 1] = dist[a[j] - 1] + c[j];
         }
      }
   }
   ll ans = dist[n-1];

   bool negative[n];
   rep(i,n) negative[i] = false;

   rep(i,n)
   {
      rep(j,m)
      {
         if(dist[a[j] -1] == INF) continue;
         if(dist[b[j] -1] > dist[a[j] - 1] + c[j])
         {
            dist[b[j] -1] = dist[a[j] - 1] + c[j];
            negative[b[j]-1] = true;
         }
         if(negative[a[j] -1])
         {
            negative[b[j] -1] = true;
         }
         //printf("d[b]: %ld  d[a]: %ld c: %ld\n", dist[b[j] -1], dist[a[j] -1], c[j]);
      }
   }

   if(negative[n-1]) cout << "inf" << endl;
   else cout << -ans << endl;
}

Measured memory_bytes: 256
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define ld long double
#define f(i,x,n) for(int i=x;i<=n;++i)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(int i=n;i>=x;--i)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 998244353




void Solve()
{	
	int n;
	cin>>n;
	string s;
	s(string) st;
	
	f(i,1,n)
	{
		cin>>s;
		st.insert(s);
	}
	cout<<st.sz;		
}

signed main() 
{
	speed		
	
	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

 
 

Measured memory_bytes: 19248
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long a[n],cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(a[i]<a[j] && a[j]<a[k]) ///equal na eta check korar jonno
                {
                    if(a[i]+a[j]>a[k])
                    {
                        cnt++;
                    }
                }
            }
        }
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std ;
const int MAXN = 1e6+5 ;
int dp[MAXN] ;
int main()
{
    int k;cin>>k ;
    dp[1] = 7%k ;
    if(dp[1]==0) return cout<<1<<"\n",0 ;
    for(int i=2;i<MAXN;i++)
    {
        dp[i] = (dp[1]+(dp[i-1]*(10%k))%k)%k ;
        if(dp[i]==0) return cout<<i<<"\n",0 ;
    }
    return cout<<-1<<"\n",0 ;
}

Measured memory_bytes: 7500
n = gets.chop.to_i
a1 = gets.chop.split.map(&:to_i)
a2 = gets.chop.split.map(&:to_i)
max = 0
n.times do |i|
  c = a1[0..i].inject(:+) + a2[i..n-1].inject(:+)
  max = c if c > max
end
p max

Measured memory_bytes: 1788
import java.io.*;
import java.util.*;
import static java.lang.System.*;

public class Main {
	static FastScanner sc = new FastScanner(System.in);
	public static void main(String[] args) {
		int[][] graph = new int[100][100];
		int n = sc.nextInt();
		int u,k,v;
		for (int i=0; i<n; i++) {
			u = sc.nextInt()-1;
			k = sc.nextInt();
			for (int j=0; j<k; j++) {
				v = sc.nextInt()-1;
				graph[u][v] = 1;
			}
		}
		
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				out.print((j==0?"":" ")+graph[i][j]);
			}
			out.println();
		}
	}
}



class FastScanner implements Closeable {
	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	public FastScanner(InputStream in) {this.in = in;}
	private boolean hasNextByte() {
		if (ptr < buflen) {return true;}
		else{
			ptr = 0;
			try {buflen = in.read(buffer);}
			catch (IOException e) {e.printStackTrace();}
			if (buflen <= 0) {return false;}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {throw new NumberFormatException();}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){return minus ? -n : n;}
			else{throw new NumberFormatException();}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
	public void close() {
		try {in.close();}
		catch (IOException e) {}
	}
}


Measured memory_bytes: 30516
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int N;
    int tmp;
    int result=0;
    int before=-99;

    vector<int> A,B,C;
    cin >> N;
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
            cin >> tmp;
            if(i==0){
                A.push_back(tmp);
            }else{
                B.push_back(tmp);
            }
        }
    }
    for(int j=0;j<N-1;j++){
        cin >> tmp;
        C.push_back(tmp);
    }

    for(int i=0;i<N;i++){
        result += B[A[i]-1];
        if(before+1==A[i]){
            result += C[A[i]-2];
        }
        // cout << result << endl;
        before = A[i];
    }

    for(int i=0;i<A.size();i++){
        // cout << A[i] << ", ";
    }
    // cout << endl;

    for(int i=0;i<B.size();i++){
        // cout << B[i] << ", ";
    }
    // cout << endl;

    for(int i=0;i<C.size();i++){
        // cout << C[i] << ", ";
    }
    // cout << endl;

    cout<< result << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

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

using pqg = priority_queue<ll,vector<ll>, greater<ll> >; // 1,3,5..
using pql = priority_queue<ll,vector<ll> >; //5, 3, 1...

using pqg_p = priority_queue<P,vector<P>, greater<P> >; // 1,3,5..
using pql_p = priority_queue<P,vector<P> >; //5, 3, 1...

#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)

bool check(char c) {
  if ( c == 'A') return true;
  if ( c == 'T') return true;
  if ( c == 'G') return true;
  if ( c == 'C') return true;
  return false;
}

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

  string s;
  cin >> s;
  int start = 0, end = s.length();

  int m = 0;
  REP(i,s.length()) {

    int po = i;
    if ( ! check(s[i]) ) continue;
    while(po < s.length() && check(s[po])) po++;

    m = max(m, po-i);
  }
  cout << m << endl;
    


}


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

case class Dice(val d:Array[Int]) {

  private def rollOnce(dir:Char)  =
    dir match {
      case 'S' => Array(4,0,2,3,5,1)
      case 'N' => Array(1,5,2,3,0,4)
      case 'W' => Array(2,1,5,0,4,3)
      case 'E' => Array(3,1,0,5,4,2)
    }

  def roll(dirs:String)  =
    (0 until d.length).foreach { x =>
      val d2 = dirs.foldLeft(Array(0,1,2,3,4,5)) { (x,y) => rollOnce(y).map(x) }.map(d)
      d(x) = d2(x)
    }

  def getTopFace() = d(0)
}

object Main extends App {
  val faces = readLine.split(" ").map(_.toInt)
  val dice = Dice(faces)
  dice.roll(readLine)

  println(dice.getTopFace())
}

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


#define long long long int

using namespace std;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef pair<int, int> pi;


int main() {
    std::ios_base::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int index = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == t[i]){
            index++;
        }
    }

    cout << index;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
#include <cctype>
#define _GLIBCXX_DEBUG
#define ll long long

using namespace std;


int main() {
    int x;
    cin >> x;
    cout << x * x * x << endl;
}


Measured memory_bytes: 3100
#include <iostream>
using namespace std;
int n,a;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a%2==0){
            if(a%3!=0&&a%5!=0){
                cout<<"DENIED"<<endl;
                return 0;
            }
        }
    }
    cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);

		String input = reader.next();

		Map<String, List<Integer>> data = new HashMap<>();

		int result = 1000000;

		for (int i = 1; i <= input.length(); i++) {
			String key = Character.toString(input.charAt(i - 1));
			Integer value = Integer.valueOf(i);

			if (data.containsKey(key)) {
				data.get(key).add(value);
			} else {
				data.put(key, new ArrayList<>(Arrays.asList(value)));
			}
		}
		
		for (Map.Entry<String, List<Integer>> entry : data.entrySet()) {
			Integer max = 0;
			Integer previous = 0;

			for (Integer i : entry.getValue()) {
				if (i - previous > max) {
					max = i - previous - 1;
				}
				previous = i;
			}

			if (input.length() - previous > max) {
				max = input.length() - previous;
			}

			if (result > max) {
				result = max;
			}
		}

		System.out.println(result);

		reader.close();
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

 
int main() {
  string a,b,los;
  int on, tw;
  cin >> a >> b >> on >> tw >> los;

  if(a == los){
    on-=1;

  }else if(b == los){
    tw -=1;
  }

  cout << on <<" "<< tw << endl;
return 0;
}

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

int SumOfDigit(int n){
  int sum=0;
  while(n>0){
    sum+=n%10;
    n/=10;
  }
  return sum;
}
int main(){
 	int N;
  	int sum=0;
  	cin>>N;
  	sum=SumOfDigit(N);
  	if(N%sum==0) cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import itertools
n, k = map(int, input().split())
acc = list(itertools.accumulate(range(1001)))
p = list(map(int, input().split()))
for i in range(n):
    temp = p[i]
    p[i] = acc[p[i]]
    p[i] /= temp
ans = 0
p = [0] + p
acc_2 = list(itertools.accumulate(p))
for i in range(n-k+1):
    ans = max(ans, acc_2[i+k] - acc_2[i])
print(ans)




Measured memory_bytes: 25276
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			ice = new int[h * w];
			hit = new int[h * w];
			dist = new int[h][w];
			m = new char[h][w];
			v = new boolean[h][w];
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++) {
					dist[i][j] = -1;
					m[i][j] = '#';
				}
			for (int i = 0; i < h; i++) {
				char[] c = scanner.next().toCharArray();
				for (int j = 0; j < w; j++) {
					m[i][j] = c[j];
					if (m[i][j] == 'S') {
						m[i][j] = '.';
						si = i;
						sj = j;
					} else if (m[i][j] == 'G') {
						m[i][j] = '.';
						gi = i;
						gj = j;
					}
				}

			}
			ice[0] = INF;
			id = new int[h][w];
			int ID = 1;
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++) {
					if (m[i][j] != 'X' || id[i][j] > 0)
						continue;
					mark(i, j, ID);
					if (ice[ID] == 1)
						m[i][j] = '#';
					ID++;
				}
			dist[gi][gj] = 0;
			Deque<int[]> deque = new ArrayDeque<int[]>();
			deque.offer(new int[] { gi, gj });
			while (!deque.isEmpty()) {
				int[] V = deque.poll();
				int pi = V[0];
				int pj = V[1];
				for (int[] mo : d) {
					int ni = pi + mo[0];
					int nj = pj + mo[1];
					if (!isOK(ni, nj))
						continue;
					if (m[ni][nj] != '#' && dist[ni][nj] == -1) {
						dist[ni][nj] = dist[pi][pj] + 1;
						deque.offer(new int[] { ni, nj });
					}
				}
			}
			res = 0;
			v[si][sj] = true;
			while (!f(si, sj, 0)) {
				Arrays.fill(hit, 0);
				v = new boolean[h][w];
				v[si][sj] = true;
				res++;
			}
			System.out.println(res);
		}
	}

	private boolean f(int i, int j, int depth) {
		if (res < depth + dist[i][j])
			return false;
		if (gi == i && gj == j)
			return true;
		for (int r = 0;r<4;r++) {
			int ni = i + d[r][0];
			int nj = j + d[r][1];
			if (!isOK(ni, nj))
				continue;
			if (!v[ni][nj] && m[ni][nj] != '#') {
				if (ice[id[ni][nj]] /2 > hit[id[ni][nj]] ) {
					hit[id[ni][nj]]++;
					v[ni][nj] = true;
					if (f(ni, nj, depth + 1))
						return true;
					v[ni][nj] = false;
					hit[id[ni][nj]]--;
				}
			}
		}
		return false;
	}

	private void mark(int i, int j, int x) {
		id[i][j] = x;
		ice[x]++;
		for (int[] mo : d) {
			int ni = i + mo[0];
			int nj = j + mo[1];
			if (!isOK(ni, nj))
				continue;
			if (m[ni][nj] == 'X' && id[ni][nj] == 0)
				mark(ni, nj, x);
		}
	}

	private boolean isOK(int i, int j) {
		if (0 <= i && i < h && 0 <= j && j < w)
			return true;
		return false;
	}

	int w, h, si, sj, gi, gj, INF = 1 << 29, res;
	int[][] d = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };
	int[] ice, hit;
	int[][] id, dist;
	char[][] m;
	boolean[][] v;
}

Measured memory_bytes: 20968
N = gets.to_i
xy_all = []
N.times do
  a = gets.to_i
  xys = []
  a.times do
    x, y = gets.split(' ').map(&:to_i)
    xys << [x - 1, y]
  end
  xy_all << xys
end
max = 0
(0..(2 ** N - 1)).each do |i|
  people = i.to_s(2).reverse + "0" * (N - i.to_s(2).length)
  catch :ng do
    0.upto(people.length - 1) do |i|
      next if people[i] == '0'
      xy_all[i].each do |xy|
        throw :ng if people[xy[0]].to_i != xy[1]
      end
    end
    max = [people.count("1"), max].max
  end
end
puts max

Measured memory_bytes: 1788
#include<bits/stdc++.h> 
using namespace std;
int n,k,a,ans;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a;
	while(n>k){
		ans+=n/k;
		n=n%k+n/k;
	}
	ans++;
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int a,b,c;
    cin >> a >> b >> c;
    Yes(a+b-c>=0);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3576
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.array;
import std.math;

void main()
{
    bool[string] set;

    auto N = readln.chomp.to!int;
    foreach(i; 0 .. N){
        auto ss = readln.chomp;
        set[ss] = true;
    }

    foreach(c; ['S', 'H', 'C', 'D'])
        foreach(n; 1 .. 14){
            auto s = format("%s %s", c, n);
            if(s !in set) writeln(s);
        }
}

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

int main() {
    int x, y;
    cin >> x >> y;

    int group[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    cout << (group[x] == group[y] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main (void) {
    char buf[5];
    int output = 0;
    std::cin >> buf;
    for(int i = 0;i < 4; i++){
        switch (buf[i])
        {
        case '+'/* constant-expression */:
            /* code */
            output++;
            break;
        case '-' :
            output --;
            break;
        default:
            return -1;
        }
    }
    std::cout << output << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
    int i,s;
    s=0;
    int N,K;
    scanf("%d %d",&N,&K);
    int X[N];
    for (i=0;i<N;i++){
        scanf("%d",&X[i]);
    }
    for (i=0;i<N;i++){
        if(X[i] > K - X[i]){
            s += K - X[i];
        }else{
            s += X[i];
        }
    }
    printf("%d\n",2*s);
    return 0;
}

Measured memory_bytes: 128
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve() {
   int a, b; cin >> a >> b;
   a *= b;
   cout << a << '\n';
}

signed main() {   
   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
   int t = 1;  //cin >> t;
   for(int i = 1; i <= t; i++) {
      solve();
  }
}    


Measured memory_bytes: 3612
package main

import (
	"bufio"
	"errors"
	"fmt"
	"os"
	"strconv"
)

func lib_MinInt(values ...int) (min int, err error) {
	if len(values) == 0 {
		return 0, errors.New("empty slice is given")
	}
	min = values[0]
	for _, value := range values {
		if min > value {
			min = value
		}
	}
	return
}
func lib_MustMinInt(values ...int) (min int) {
	min, err := lib_MinInt(values...)
	if err != nil {
		panic(err)
	}
	return min
}
func lib_TernaryOPInt(ok bool, v1, v2 int) int {
	if ok {
		return v1
	}
	return v2
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var A int
	scanner.Scan()
	A, _ = strconv.Atoi(scanner.Text())
	var B int
	scanner.Scan()
	B, _ = strconv.Atoi(scanner.Text())
	var C int
	scanner.Scan()
	C, _ = strconv.Atoi(scanner.Text())
	var X int
	scanner.Scan()
	X, _ = strconv.Atoi(scanner.Text())
	var Y int
	scanner.Scan()
	Y, _ = strconv.Atoi(scanner.Text())
	fmt.Println(solve(A, B, C, X, Y))
}
func solve(A int, B int, C int, X int, Y int) int {
	noMix := A*X + B*Y
	allMix := lib_TernaryOPInt(X > Y, C*2*X, C*2*Y)
	mix := lib_TernaryOPInt(X > Y, C*2*Y+A*(X-Y), C*2*X+B*(Y-X))
	return lib_MustMinInt(noMix, allMix, mix)
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

template<class T>
inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : false; }

const LL infLL = 1e18;
mt19937 rng( (int)chrono::steady_clock::now().time_since_epoch().count() );

struct Bit {
  vector<LL> mn;
  bool rev;
  Bit(int nNode, int _rev) : rev(_rev) { mn.assign(nNode, infLL); }

  void upd(int pos, LL val) {
    if (rev) pos = sz(mn) - 1 - pos;
    for (int i = pos; i < sz(mn); i |= i + 1) asMn(mn[i], val);
  }
  LL getMn(int pos) {
    if (rev) pos = sz(mn) - 1 - pos;
    LL ret = infLL;
    for (int i = pos; ~i; i = (i & (i + 1) ) - 1) asMn(ret, mn[i]);
    return ret;
  }
};

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

  #ifdef FourLeafClover
  freopen("input", "r", stdin);
  #endif // FourLeafClover

  int n, q, a, b; cin >> n >> q >> a >> b; --a; --b;
  vector<int> x(q);
  for (auto &i : x) cin >> i, --i;

  if (q == 1) return cout << min(abs(a - x[0]), abs(b - x[0]) ), 0;

  vector<LL> pref(sz(x) );
  for (int i = 1; i < sz(x); ++i) pref[i] = pref[i - 1] + abs(x[i] - x[i - 1]);

  vector<LL> f(q, infLL);
  Bit smaller(n, false), bigger(n, true);
  for (int i = 0; i + 1 < sz(x); ++i) {
    asMn(f[i], pref[i] + abs(a - x[0]) + abs(b - x[i + 1]) );
    asMn(f[i], pref[i] + abs(b - x[0]) + abs(a - x[i + 1]) );

    asMn(f[i], pref[i] + x[i + 1] + smaller.getMn(x[i + 1]) );
    asMn(f[i], pref[i] + bigger.getMn(x[i + 1]) - x[i + 1]);

    smaller.upd(x[i], f[i] - pref[i + 1] - x[i]);
    bigger.upd(x[i], f[i] - pref[i + 1] + x[i]);
  }

  LL ans = infLL;
  for (int i = 0; i + 1 < sz(f); ++i) asMn(ans, f[i] + pref.back() - pref[i + 1]);

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 7296
# K<=5ということから6文字以上のsubstringには5個以上、辞書順で早いprefixを5個以上もつので
# 長さが5以下の文字列のみをみればいい

S = input()
K = int(input())
substrings = []
for i in range(1, min(len(S)+1, 6)):  # 文字数
    for n in range(len(S) - i + 1):
        sub = S[n:n + i]
        if sub not in substrings:
            substrings.append(sub)
# print(substrings)
substrings.sort()
print(substrings[K-1])

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    cin>>n;
    vstr s(n);
    vstr p(n);
    rep(i,n)cin>>s[i]>>p[i];
    vvstr a(n,vstr(3));
    rep(i,n){
        a[i][0]=s[i];
        a[i][1]=p[i];
        a[i][2]=to_string(i+1);
    }
    rep(i,n-1){
        rep2(j,i+1,n){
            if(a[i][0]>a[j][0]){
                vstr tmp={a[i][0],a[i][1],a[i][2]};
                a[i][0]=a[j][0];
                a[i][1]=a[j][1];
                a[i][2]=a[j][2];
                a[j][0]=tmp[0];
                a[j][1]=tmp[1];
                a[j][2]=tmp[2];
            }
            else if(a[i][0]==a[j][0]){
                if(a[i][1].size()==a[j][1].size()){
                    if(a[i][1]<a[j][1]){
                    vstr tmp={a[i][0],a[i][1],a[i][2]};
                    a[i][0]=a[j][0];
                    a[i][1]=a[j][1];
                    a[i][2]=a[j][2];
                    a[j][0]=tmp[0];
                    a[j][1]=tmp[1];
                    a[j][2]=tmp[2];
                }
                }
                if(a[i][1].size()<a[j][1].size()){
                vstr tmp={a[i][0],a[i][1],a[i][2]};
                a[i][0]=a[j][0];
                a[i][1]=a[j][1];
                a[i][2]=a[j][2];
                a[j][0]=tmp[0];
                a[j][1]=tmp[1];
                a[j][2]=tmp[2];
                }
            }
        }
    }
    rep(i,n)cout<<a[i][2]<<endl;
}

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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if ((x < 0) || (y < 0)) { cout << "No" << endl; return 0;}
    if (((x + r) <= W) && ((y + r) <= H)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k;
  double n;
  cin >> n >> k;
  double K = k;
  double ans = 0.0000000000;
  for(int i = 1;i <= n;i++){
    if(i >= k)ans += 1;
    else{
      int m;
      for(int j = 1;;j++){
        if(i*pow(2,j) >= k){
          m = j;
          break;
        }
      }
      ans += 1.000000000/pow(2,m);
    }
  }
  ans = ans / n;
  cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << max({10*a+b+c, a+10*b+c, a+b+10*c}) << endl;
}

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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    long long A, B, C, K;
    ist >> A >> B >> C >> K;

    /* ------- 計算 ------- */

    if (K <= A)
    {
        ost << K << endl;
        return;
    }

    if (K <= A + B)
    {
        ost << A << endl;
        return;
    }

    C = K - (A + B);
    ost << A - C << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    // A ... h1 x w1
    // B ... h2 x w2
    // A < Bならば 1、それ以外ならば0をreturnする
    static int lessThan(int high, int wide, int h, int w) {
        if ((high * high) + (wide * wide) < (h * h) + (w * w) || (high * high) + (wide * wide) == (h * h) + (w * w) && high < h) {
            return 1;
        } else {
            return 0;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int high = scanner.nextInt();
        int wide = scanner.nextInt();
        int a = 0;

        int ah = 149;
        int aw = 150;
        while (high != 0 || wide != 0) {
            for (int h = 1; h < 150; h++) {
                for (int w = h + 1; w < 150; w++) {
                    if (1 == lessThan(high, wide, h, w)) {
                        if (1 == lessThan(h, w, ah, aw)) {
                            ah = h;
                            aw = w;
                        }
                    }
                }
            }
            System.out.println(ah + " " + aw);

            high = scanner.nextInt();
            wide = scanner.nextInt();
            a = 0;

            ah = 149;
            aw = 150;
        }
    }
}





Measured memory_bytes: 27632
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

ll N;
vector<ll> A;
bool zero = false;
int zero_idx = 0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      zero = true;
      zero_idx = i;
    }
  }

  ll ans = 0;
  if (zero) {
    for (int i = 0; i < zero_idx; i++) {
      ans += abs(A[i]);
    }
    int num_minus = 0;
    for (int i = zero_idx; i < N; i++) {
      if (A[i] < 0) {
        num_minus++;
      }
    }
    if (zero_idx != N) {
      vector<ll> abs_A;
      for (int i = zero_idx; i < N; i++) {
        abs_A.push_back(abs(A[i]));
      }
      if (num_minus % 2 == 0) {
        for (int i = 0; i < abs_A.size(); i++) {
          ans += abs_A[i];
        }
      } else {
        sort(abs_A.begin(), abs_A.end());
        ans -= abs_A[0];
        for (int i = 1; i < abs_A.size(); i++) {
          ans += abs_A[i];
        }
      }
    }
  } else {
    int num_minus = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] < 0) {
        num_minus++;
      }
    }
    vector<ll> abs_A(N);
    for (int i = 0; i < N; i++) {
      abs_A[i] = abs(A[i]);
    }
    if (num_minus % 2 == 0) {
      for (int i = 0; i < N; i++) {
        ans += abs_A[i];
      }
    } else {
      sort(abs_A.begin(), abs_A.end());
      ans -= abs_A[0];
      for (int i = 1; i < N; i++) {
        ans += abs_A[i];
      }
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2168
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N = int(input())
W = [int(i) for i in input().split()]

L = [-1 for i in range(N+1)]
R = [-1 for i in range(N+1)]
for i in range(1,N+1):
    L[i] = sum(W[:i])
    R[i] = sum(W[i:])

ans = mod
for i in range(1,N+1):
    ans = min(ans,abs(L[i]-R[i]))


print(ans)


Measured memory_bytes: 6604
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  long long K;
  cin >> N >> K;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
    A[i]--;
  }
  
  
  int loop = 0;
  int start = 0; 
  bool Seen[N];
  for(int i=0;i<N;i++) Seen[i]=false;
  Seen[0]=true;
  vector<int> B;
  B.push_back(0);
  int arriveat=0;
  
  for(int i=0;i<N;i++){
    loop++;
    arriveat = A[arriveat];
    if(!Seen[arriveat]){
      Seen[arriveat] = true;
      B.push_back(arriveat);
    }
    else{
      start = arriveat;
      break;
    }
  }
  
  int lpfirst;
  int lpnum;
  for(int i=0;i<loop;i++){
    if(B.at(i)==start){
      lpnum = loop - i;
      lpfirst = i;
      break;
    }
  }
  
  if(lpfirst > K){
    cout << B.at(K)+1 << endl;
  }else{
    int res;
    res = (K - lpfirst) % lpnum;
    cout << B.at(lpfirst + res)+1 << endl;
  }
  
}

Measured memory_bytes: 5236
n = int(input())
s = input()
ans = s

let = 0
let2 = ""
for i in range(n):
	if s[i] == "(":
		let += 1
	else:
		if let > 0:
			let -= 1
		else:
			let2 += "("
print (let2 + s + ")"*let)

Measured memory_bytes: 3060
import numpy as np


def main():
    n, k = map(int, input().split())
    a = np.array(sorted(list(map(int, input().split()))))
    p = 10**9 + 7

    '''
    (nCk mod p)の計算方法
    https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#3-2-mod-p-%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B%E9%80%86%E5%85%83
    '''
    def nCr_mod_p(n, r, p):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n-r] % p

    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # factinv 計算用 (n^(-1) mod p)

    for i in range(2, n+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p) # ((n!)^(-1) mod p) = ( ((n-1)!)^(-1) mod p ) * (n^(-1) mod p)

    count = 0
    for i in range(n):
        count += nCr_mod_p(i, k-1, p) * (a[i] - a[-i-1]) % p
    print((count + p) % p)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26464
/*{{{*/
#include<bits/stdc++.h>
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(), (X).end()
#define rep(I, N) for (int I = 0; I < (N); ++I)
#define repp(I, A, B) for (int I = (A); I <= (B); ++I)
#define repr(I, N) for (int I = (N)-1; I >= 0; --I)
#define reppr(I, A, B) for (int I = (A); I >= (B); --I)
#define fors(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define get_pos(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define mp make_pair
#define pb emplace_back
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(X)
#define in insert
#define cn count
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef set<int> si;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T, class U> void _W(const pair<T, U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
/*}}}*/
void solve() {
	int n; R(n);
	int a;
	si s;
	rep(i, n) cin >> a, s.in(a);
	if (sz(s) == n) {
		W("YES");
	} else {
		W("NO");
	}
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

#define MULTITEST 0
#if MULTITEST
	CASET {
		solve();
	}
#else
	solve();
#endif
	return 0;
}


Measured memory_bytes: 13160
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,k;
    cin>>n>>k;
    vector<ll>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    ll res=0;
    sort(v.rbegin(),v.rend());
    for(int i=k;i<n;i++){
        res+=v[i];
    }
    cout<<res<<endl;
    return 0;
    }


Measured memory_bytes: 1792