akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
	long n = long.Parse(Console.ReadLine());//long.Parseは文字列を整数に変換。
	long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
  long[,] numZeros = new long[n,21];//0が一の位で二進数
  long[] zeroMemo = new long[21];
  long answer = 0;

    for(long i = 0; i < n; i++)//二進数の配列
    {
      long[] zeroMem = BinaryArray(nums[i]);
      for(long j = 0; j < 21; j++)
      {
        numZeros[i,j] = zeroMem[j];
      }
    }

    long look = 0;
    long checkNum = 0;
    for(long i = 0; i < n; i++)
    {
      bool isProblem = false;
      for(long j = 0; j < 21; j++)
      {
        if(numZeros[i,j] == 1) zeroMemo[j]++;
        if(zeroMemo[j] == 2) isProblem = true;
      }
      //Console.WriteLine(" "+zeroMemo[3]+zeroMemo[2]+zeroMemo[1]+zeroMemo[0]);
      if(isProblem)
      {
      while(true)
        {
          look--;
          bool isProblemSub = false;
          for(long j = 0; j < 21; j++)
          {
            if(numZeros[checkNum,j] == 1) zeroMemo[j]--;
            if(zeroMemo[j] == 2) isProblemSub = true;
          }
          checkNum++;
          //Console.WriteLine(" "+zeroMemo[3]+zeroMemo[2]+zeroMemo[1]+zeroMemo[0]+"m");
          if(!(isProblemSub)) break;
        }
      }
      answer += look + 1;
      //Console.WriteLine(answer);
      look++;
    }
  
	Console.WriteLine(answer);
	}

  static long[] BinaryArray(long n)//引数nを、[0]が一の位から順に配列として返す
  {
    long returnNum = 21;//返す桁数
    long[] nums = new long[returnNum];
    long memo = 2;
    for(long i = 0; i < returnNum; i++)
    {
      if(n % memo == memo / 2)
      {
        nums[i] = 1;
        n -= memo / 2;
      }
    memo *= 2;
    }
    //Console.WriteLine(" "+nums[3]+nums[2]+nums[1]+nums[0]);
    return nums;
  }
/*
  static long[] ArrayAdd(long[] a, long[] b)//引数であるそれぞれの配列の、和の配列を返す
  {
  long[] c = new long[a.Length];
    for(long i = 0; i < a.Length; i++)
    {
      c[i] = a[i] + b[i];
    }
  return c;
  }

  static long[] ArraySubtract(long[] a, long[] b)//引数であるそれぞれの配列の、差(a-b)の配列を返す
  {
  long[] c = new long[a.Length];
    for(long i = 0; i < a.Length; i++)
    {
      c[i] = a[i] - b[i];
    }
  return c;
  }
*/

}


Measured memory_bytes: 61832
use std::collections::HashSet;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n:usize = read();
    let v:Vec<usize> = (0..n).map(|_| read()).collect();
    let mut set = HashSet::new();
    for i in 0..n {
        for j in 0..n {
            for k in 0..n {
                if v[i] == v[j] || v[i] == v[k] || v[k] == v[j] {
                    continue;
                }
                if v[i] + v[j] > v[k] &&  v[i] + v[k] > v[j] &&  v[j] + v[k] > v[i] {
                    let mut x = vec![i+1, j+1, k+1];
                    x.sort();
                    set.insert(x);
                }
            }
        }
    }
    println!("{}", set.len());
}


Measured memory_bytes: 15244
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>
using namespace std;
#define int long long

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int n, k;
    cin >> n >> k;
    vector<int> v;
    for (int i = 0; i != n; ++i) {
        int h;
        cin >> h;
        v.push_back(h);
    }
    sort(v.begin(), v.end());
    if (k >= n) {
        cout << 0;
        return 0;
    }
    int s = 0;
    for (int i = 0; i != n - k; ++i)
        s += v[i];
    cout << s;
    return 0;
}

Measured memory_bytes: 3444
import java.util.Scanner;

/**
 * Created by nakatsukatakahiro on 2017/06/10.
 */
class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        String pares = scanner.next();  // parentheses

        String ans = pares;
        int leftPare = 0;
        for (int i = 0; i < N; i++) {
            String pare = pares.substring(i, i + 1);
            if (pare.equals(")") && leftPare == 0) {
                ans = "(" + ans;
            } else if (pare.equals(")") && leftPare > 0) {
                leftPare--;
            } else {
                leftPare++;
            }
        }

        for (int i = 0; i < leftPare; i++) {
            ans = ans + ")";
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 21844
N=int(input())
A=[]

str='Yes'
total=0
time=0
for i in range(N):
    a,b, = map(int, input().split())
    A.append([b,a])

A.sort()


for j in range(N):
    if time<=A[j][0]:
        time = A[j][0]

    A[j][0]=100000000000
    total +=A[j][1]

    if total>time:
        str='No'
print(str)

Measured memory_bytes: 35640
// 929

#include <cstdio>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> PP;
#define INF (2*100000+1000)

class SegmentTree {
public:
  P Storage[1<<20]; // 0=> value 1=> index
  int N;
  void init(int n) {
    N=1;
    while(N<n) N*=2;

    for(int i=0;i<N*2;++i) {
      Storage[i].first=INF;
      Storage[i].second=0;
    }
  }

  void updateLeaf(int i, int value) {
    i += N-1;
    Storage[i].first=value;
    Storage[i].second=i-(N-1);
    while(i>0) {
      i = (i-1) / 2;
      Storage[i] = min(Storage[i*2+1], Storage[i*2+2]);
    }
  }

  P getMin(int a,int b,int k,int l, int r) {
    if(b<=l || a>=r) return P(INF, 0);
    if(a<=l && b>=r) {
      return Storage[k];
    } else {
      P tl = getMin(a,b,k*2+1,l,(l+r)/2);
      P tr = getMin(a,b,k*2+2,(l+r)/2,r);
      return min(tl,tr);
    }
  }
};

SegmentTree evenTree;
SegmentTree oddTree;
priority_queue<PP, vector<PP>, greater<PP> > Q;
int N;

int main() {
  scanf("%d", &N);
  evenTree.init(N);
  oddTree.init(N);
  for(int i=0;i<N;++i) {
    int p;
    scanf("%d", &p);
    if(i%2==0) {
      evenTree.updateLeaf(i, p);
    } else {
      oddTree.updateLeaf(i, p);
    }
  }
  vector<int> answer;

  Q.push(PP(evenTree.getMin(0,N,0,0,evenTree.N),P(0, N)));
  while(!Q.empty()) {
    PP pp=Q.top();Q.pop();
    P range = pp.second;
    int index=pp.first.second;
    answer.push_back(pp.first.first);
    P minValue;
    if (index%2==0) {
      minValue=oddTree.getMin(index+1, range.second,0,0,oddTree.N);
    } else {
      minValue=evenTree.getMin(index+1, range.second,0,0,evenTree.N);
    }
    answer.push_back(minValue.first);
    P newRanegs[]={
      P(range.first, pp.first.second),
      P(pp.first.second+1, minValue.second),
      P(minValue.second+1, range.second)
    };
    for(int i=0;i<3;++i) {
      P r=newRanegs[i];
      if(r.second==r.first) continue;
      P v;
      if(r.first%2==0) {
        v=evenTree.getMin(r.first,r.second,0,0,evenTree.N);
      } else {
        v=oddTree.getMin(r.first,r.second,0,0,oddTree.N);
      }
      Q.push(PP(v, r));
    }
  }

  for(int i=0;i<N;++i) {
    printf("%d ", answer[i]);
  }
  printf("\n");


  return 0;
}


Measured memory_bytes: 19444
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int h,w,ans=0;
vvc c;

int main(){
	ios::sync_with_stdio(0);
	cin>>h>>w;
	c=vvc(w,vc(h));
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>c[j][i];
	for(int i=0;i<w-1;i++){
		vvi cost(h+1,vi(h+1));
		vi dp(h+1);
		for(int j=1;j<=h;j++) for(int k=1;k<=h;k++){
			cost[j][k]=cost[j-1][k-1]+(c[i][j-1]==c[i+1][k-1]);
		}
		for(int j=1;j<=h;j++) for(int k=1;k<=h;k++){
			dp[k]=min(dp[k],dp[k-1])+cost[j][k];
		}
		ans+=dp[h];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 788
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,H,W,A,c[10][10];
  cin>>H>>W;
    for(int i=0;i<=9;i++){
      for(int j=0;j<=9;j++){
        cin>>c[i][j];
      }
    }
    for(int k=0;k<=9;k++){
      for(int i=0;i<=9;i++){
        for(int j=0;j<=9;j++){
          c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
        }
      }
    }
    for(int i=0;i<=H-1;i++){
      for(int j=0;j<=W-1;j++){
        cin>>A;
        a+=c[A>=0?A:1][1];
      }
    }
  cout<<a;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	static List<Integer> U=new ArrayList<>(); 
	static int m;
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt();
		for(int i=0;i<n;i++)U.add(Integer.parseInt(in.next()));
		
		int q=in.nextInt();
		for(int i=0;i<q;i++){
			m=in.nextInt();
			System.out.println((solve(0,0))? "yes":"no");
		}
	}
	
	static boolean solve(int sum,int i){
		//System.out.println(sum);
		if(sum==m)return true;
		else if(sum>m)return false;
		
		for(int j=i;j<U.size();j++){
			if(solve(sum+U.get(j),j+1))return true;
		}
		return false;
	}


}



Measured memory_bytes: 27060
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define lint long long

int main() {
	
	lint X, Y, Z, K; cin >> X >> Y >> Z >> K;
	vector<lint> A(X);
	for (lint i = 0; i < X; i++)
	{
		cin >> A[i];
	}
	vector<lint> B(Y);
	for (lint i = 0; i < Y; i++)
	{
		cin >> B[i];
	}
	vector<lint> C(Z);
	for (lint i = 0; i < Z; i++)
	{
		cin >> C[i];

	}
	vector<lint> AB(X*Y);
	int l = 0;
	for (lint i = 0; i < X; i++)
	{
		for (lint j = 0; j < Y; j++)
		{
			AB[l] = A[i] + B[j];
			//cout << AB[l] << endl;
			l++;
			
		}
	}
	sort(AB.begin(), AB.end());
	reverse(AB.begin(), AB.end());
	vector<lint> ABC(3000 * Z);
	lint ll = 0;
	lint r; if (3000 > X*Y) {
		r = X * Y;
	}
	else {
		r = 3000;
	}
	for (lint i = 0; i < r; i++)
	{	
		for (lint j = 0; j < Z; j++)
		{
			ABC[ll] = AB[i] + C[j];
			ll++;
			//cout << ABC[ll] << endl;
		}

	}
	sort(ABC.begin(), ABC.end());
	reverse(ABC.begin(), ABC.end());
	//cout << ABC[0] << endl;
	
	for (lint i = 0; i < K; i++)
	{
		cout << ABC[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string Str;
  cin >> Str;

  int N=0;
  int S=0;
  int W=0;
  int E=0;
  rep(i, 0, Str.size()){
    switch(Str[i]){
      case 'S':
        S=1;
        break;
      case 'N':
        N=1;
        break;
      case 'W':
        W=1;
        break;
      case 'E':
        E=1;
        break;
    }
  }

  if((N+S)%2==0 && (W+E)%2==0){
    cout << "Yes\n";
    return 0;
  }

  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
MAX = 2**31-1

def rmq(a, b, k, l, r, node)
  return MAX if r <= a || b <= l
  return node[k] if a <= l && r <= b
  m = (l+r)/2
  vl = rmq(a, b, 2*k+1, l, m, node)
  vr = rmq(a, b, 2*k+2, m, r, node)
  return vl < vr ? vl : vr
end

n, len = gets.split.map(&:to_i)
m = 1
while m < n
  m *= 2
end
node = Array.new(2*m-1){MAX}
arr = gets.split.map(&:to_i)


monotonically_increase = true
arr.size.times{|i|
  monotonically_increase = false if i > 0 && arr[i]-arr[i-1] < 0
  k = i + m - 1
  node[k] = arr[i]
  while k > 0
    k = (k-1)/2
    node[k] = node[2*k+1] < node[2*k+2] ? node[2*k+1] : node[2*k+2]
  end
}

if monotonically_increase
  puts arr[0..-len].join(" ")
  exit
end

pos = {}
len.times{|i|
  pos[arr[i]] = i
}
i = len
j = 0

min = rmq(j, i, 0, 0, m, node)
idx = pos[min]

print min

loop do
  break if i >= n

  pos[arr[i]] = i
  pos.delete(arr[j]) if pos[arr[j]] == j

  if min >= arr[i] then
    min = arr[i]
    idx = i
  elsif idx == j then # drop out minimum number from the window
    min = rmq(j+1, i+1, 0, 0, m, node)
    idx = pos[min]
  end
  print " #{min}"
  i += 1
  j += 1
end

puts

Measured memory_bytes: 98848
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;


int main()
{
  int h,w,n;
  cin>>h>>w>>n;
  char map[h][w];
  bool closed[h][w];
  int sx,sy;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      {
	cin>>map[i][j];
	if(map[i][j]=='S')
	  {
	    sx=i;
	    sy=j;
	  }
      }
  int ans=0;
  int dx[]={1,-1,0,0};
  int dy[]={0,0,-1,1};
  for(int i=1;i<=n;i++)
    {
      queue<pair<pair<int,int>,int> >qu;
      while(!qu.empty())
	qu.pop();
      qu.push(make_pair(make_pair(sx,sy),0));
      memset(closed,false,sizeof(closed));
      while(true)
	{
	  pair<pair<int,int> ,int> tmp=qu.front();
	  qu.pop();
	  int x=tmp.first.first;
	  int y=tmp.first.second;
	  int step=tmp.second;
	  //	  cout<<x<<" "<<y<<" "<<step<<endl;
	  if(map[x][y]=='0'+i)
	    {
	      ans+=step;
	      //cout<<"fin :"<<i<<" step;"<<step<<endl;
	      sx=x;
	      sy=y;
	      break;
	    }
	  if(closed[x][y])
	    continue;
	  closed[x][y]=true;
	  for(int xx=0;xx<4;xx++)
	    {
	      if(x+dx[xx]>=0 && x+dx[xx]<h &&
		 y+dy[xx]>=0 && y+dy[xx]<w &&
		 !closed[x+dx[xx]][y+dy[xx]] &&
		 map[x+dx[xx]][y+dy[xx]]!='X'
		 )
		qu.push(make_pair(make_pair(x+dx[xx],y+dy[xx]),step+1));
	    }
	}
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 3172
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int a[3], k;
int main(){
	for(int i = 0; i < 3; i++){
		scanf("%d", &a[i]);
	}
	scanf("%d", &k);
	int max = 0;
	for(int i = 0; i < 3; i++){
		if(max < a[i]){
			max = a[i];
		}
	}
	int max1 = max;
	for(int i = 0; i < k; i++){
		max *= 2;
	}
	printf("%d\n", a[1] + a[2] + a[0] - max1 + max);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	string s;
	cin >> s;
	for (int i =0;i<s.size();i++) {
		int count =0;
		for (int j =0;j<s.size();j++) {
			if (s[i] == s[j]) count++;
		}
		if (count !=2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int W,H,x,y,r;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if(x>=W || x<=0){

printf("No\n");


}else if(y>=H || y<=0){


printf("No\n");


}else if(x+r>W || x-r<0){


printf("No\n");


}else if(y+r>H || y-r<0){


printf("No\n");


}else


printf("Yes\n");


return 0;

}

Measured memory_bytes: 580
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
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 (b<a) { a=b; return 1; } return 0; }
using namespace std;


int main(){
  int N,ans=0,L=0;
  cin>>N;
  int A[13];
  REP(i,13) A[i]=0;
  
  REP(i,N){
    int a;
    cin>>a;
    A[a/400]++;
  }
  
  L=A[8]+A[9]+A[10]+A[11]+A[12];
  
  REP(i,8){
    if(A[i]>0) ans++;
  }
  
  cout<<max(1,ans)<<" "<<ans+L<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll a[N];
  ll sum = 0;
  REP(i, N) {
    cin >> a[i];
    sum += a[i];
  }
  ll diff[N - 1];
  ll tmp = 0;

  REP(i, N - 1) {
    tmp += a[i];
    diff[i] = abs(tmp - (sum - tmp));
  }
  sort(diff, diff + N - 1);

  cout << diff[0];

  return 0;
}

Measured memory_bytes: 3328
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		long[] l=new long[n];
		l[0]=a[0];
		long[] r=new long[n];
		r[0]=a[n-1];
		for(int i=1;i<n;i++) {
			l[i]=gcd(l[i-1],a[i]);
			r[i]=gcd(r[i-1],a[n-1-i]);
		}
		long max=0;
		for(int i=0;i<n;i++) {
			long g=0;
			if(i==0) {
				g=r[n-2];
			}else if(i==n-1) {
				g=l[n-2];
			}else {
				g=gcd(l[i-1],r[n-1-i-1]);
			}
			max=Math.max(max, g);
		}
		System.out.println(max);
	}
	static long gcd(long a, long b) {
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    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());}
}


Measured memory_bytes: 25684
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int min = Integer.parseInt(sc.next());
    int cnt = 1;
    for (int i = 1; i < n; i++) {
      int pi = Integer.parseInt(sc.next());
      if (pi <= min) {
        min = pi;
		cnt++;
      }
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 48424
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using Plint = pair<lint, lint>;

lint N, X, D;

vector<int> par;
vector<vector<int>> chi;
vector<lint> m, ms, ns;

void dfsms(int i)
{
    ms[i] = m[i];
    ns[i] = 1;
    for (auto v : chi[i])
    {
        dfsms(v);
        ms[i] += ms[v];
        ns[i] += ns[v];
    }
}

bool efficient(const Plint &a, const Plint &b) {
    return a.first * b.second > b.first * a.second;
}

int main()
{
    cin >> N >> X >> D;
    m.resize(N);
    par.resize(N);
    chi.resize(N);
    cin >> m[0]; par[0] = -1;
    for (int i = 1; i < N; i++)
    {
        cin >> m[i] >> par[i];
        par[i]--;
        chi[par[i]].push_back(i);
    }

    ms.resize(N);
    ns.resize(N);
    dfsms(0);

    vector<Plint> info;
    for (int i=0; i<N; i++) info.push_back(Plint(ns[i], ms[i]));
    sort(info.begin(), info.end(), efficient);
    // for (auto v : info) cout << v.first << " " << v.second << endl;

    // vector<vector<lint>> dp(N+1, vector<lint>(2501, -1));
    array<array<lint, 2501>, 51> dp;
    for (auto &vec : dp) for (auto &v : vec) v = -1;

    dp[0][0] = 0;
    vector<lint> maxnum(N+1);

    for (int i = 1; i <= N; i++)
    {
        lint v = info[i-1].first;
        lint w = info[i-1].second;

        maxnum[i] = maxnum[i-1];
        for (int j = 0; j < 2501; j++) if (dp[i-1][j] >= 0)
        {
            if (v != N) maxnum[i] = max(maxnum[i], maxnum[i-1] - j + min((X - dp[i-1][j]) / w, D) * v);
            else maxnum[i] = max(maxnum[i], maxnum[i-1] - j + (X - dp[i-1][j]) / w * v);
        }

        for (int j=0; j<2501; j++) if (dp[i-1][j] >= 0)
        {
            for (int k=(maxnum[i]-maxnum[i-1]+j)%v; k<2501; k+=v)
            {
                lint need = (maxnum[i]-k) - (maxnum[i-1]-j);
                if (need < 0) continue;
                if (v != N && need > D * v) continue;
                lint dp_tmp = dp[i-1][j] + need / v * w;
                if (dp_tmp > X) continue;
                if (dp[i][k] < 0 || dp[i][k] > dp_tmp) dp[i][k] = dp_tmp;
            }
        }
    }
    // for (auto vec : dp)
    // {
    //     for (auto v : vec) cout << v << " ";
    //     cout << endl;
    // }
    // for (auto v : maxnum) cout << v << " ";
    cout << maxnum[N] << endl;
}


Measured memory_bytes: 1280
# -*- coding: utf-8 -*-
import math

X = int(input())

bmax = round(math.sqrt(X))

bp = 1
for b in range(2, bmax + 1, 1):
    p = 2
    while(pow(b, p) <= X):
        p += 1
    p += -1
    if(bp < pow(b, p)):
        bp = pow(b, p)

print(bp)

Measured memory_bytes: 3060
// by adiforluls
#pragma GCC optimize ("-O2")
#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;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define mii             map<int,int>
#define vi              vector<int>
#define vll             vector<long long>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul             1000000007
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define mod             998244353 
#define pll             pair<ll,ll>
#define endl            '\n'
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
#define N    100005

void solve()
{
    int n; cin>>n;
    int idx = 0;
    rep(i,0,n)
    {
        int x; cin>>x;
        if(x == idx+1) idx++;
    }
    int ans;
    if(!idx) ans = -1;
    else ans = n - idx;
    cout<<ans; 
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; /*cin>>t;*/ t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100009
#define MAXM 320
#define EPS 1e-9
#define MOD 1000000007
#define INF 1000000009
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
#define pb push_back
#define all(x) x.begin(), x.end()
typedef long long ll;

int cnt[26];

int main() {
	string str;
	cin >> str;
	for (int i = 0; str[i]; i++) {
		cnt[str[i]-'a']++;
		if (cnt[str[i]-'a'] > 1) { puts("-1"); return 0; }
	}
	if (str == "zyxwvutsrqponmlkjihgfedcba") {
		puts("-1"); return 0;
	}
	for (int i = 0; i < 26; i++) {
		if (cnt[i] == 0) {
			printf("%s%c\n", str.c_str(), i + 'a');
			return 0;
		}
	}
	string cpy = str;
	next_permutation(str.begin(), str.end());
	for (int i = 0; str[i]; i++) {
		printf("%c", str[i]);
		if (cpy[i] != str[i]) break;
	}
	printf("\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;string s;cin>>n>>s;
  bool isok=(n%2==0);
  if(isok) isok=(s.substr(0,n/2)==s.substr(n/2,n/2));
  print(isok?"Yes":"No");
  return 0;
}

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

using namespace std;
typedef long long ll;

vector<ll> f(ll n)
{
  vector<ll> v(n+1,1);

  for(int i=2;i<=n;++i)
  {
    for(int j=i;j<=n;j+=i)
    {
      v[j]++;
    }
  }

  return v;
}

int main()
{
  ll n;cin>>n;
  ll res=0;
  vector<ll> v = f(n);

  for(int i=1;i<=n;++i)
  {
    res+=(i*v[i]);
  }

  cout<<res;
}


Measured memory_bytes: 81408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
int main(){
	int n,k,ans=1;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		ans=min(ans*2,ans+k);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N+1,0);
	vector<ll> counter(200005,0);
	for(ll i=1;i<N+1;i++){
		cin>>A[i];
		counter[A[i]]++;
	;}
	ll sum=0;
	for(ll i=1;i<=200000;i++){
		sum+=counter[i]*(counter[i]-1)/2
	;}
	for(ll i=1;i<N+1;i++){
		cout<<sum-counter[A[i]]+1<<endl;
	;}

return 0;
}  



Measured memory_bytes: 5760
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
  static StringTokenizer st;
  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

      read(in.readLine());
      int n = atoi(next());
      int m = atoi(next());
      int r = atoi(next());

      int[] t = mapInt(r, read(in.readLine()));

      final int INF = 1 << 28;
      Graph G = new Graph(n, r, t);

      for (int a[] : G.graph) Arrays.fill(a, INF);
      for (int i = 0; i < m; i++) {
        int[] edge = mapInt(3, read(in.readLine()));
        G.graph[edge[0]-1][edge[1]-1] = edge[2];
        G.graph[edge[1]-1][edge[0]-1] = edge[2];
      }

      // warshall-Froyd
      for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
          for (int j = 0; j < n; j++) {
            G.graph[i][j] = min(G.graph[i][j], G.graph[i][k] + G.graph[k][j]);
          }
        }
      }

      final int ans = G.compute();
      out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

 class Graph {
    private int enm;
    private int[] pmt;
    private int ret;
    private boolean[] visited;

    public int[][] graph;
    // option
    private int t[];

    public Graph(int n, int enm, int[] t) {
      this.enm = enm;
      this.t = t;
      ret = Integer.MAX_VALUE;
      graph = new int[n][n];
      pmt = new int[enm];
      visited = new boolean[n];
    }

    public int compute() {
      dfs(0);
      return ret;
    }

    private void dfs(int cnt) {
      if(cnt == enm) {
        evalute();
        return;
      }
  
      for (int v: t) {
        if(visited[--v]) continue;

        pmt[cnt] = v;
        visited[v] = true;
        dfs(cnt+1);
        visited[v] = false;
      }
    }
  
    private void evalute() {
      int result = 0;
      for (int i = 1; i < enm; i++) result += graph[pmt[i-1]][pmt[i]];
      ret = min(ret, result);
    }
  }

  static StringTokenizer read(String ln) { st = new StringTokenizer(ln); return st;}
  static String next() { return st.nextToken(); }
  static int  atoi(String s) { return Integer.parseInt(s); }
  static long atol(String s) { return Long.parseLong(s); }
  static int[] mapInt(int len, StringTokenizer st) {
    int[] ret = new int[len];
    for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(st.nextToken());
    return ret;
  }
  static int[] mapInt(String[] sa) {
    int[] ret = new int[sa.length];
    for (int i = 0; i < sa.length; i++) ret[i] = Integer.parseInt(sa[i]);
    return ret;
  }
  static void mapInt(int[] ret, String[] sa) {
    for (int i = 0; i < sa.length; i++) ret[i] = Integer.parseInt(sa[i]);
  }
  static long[] mapLong(String[] sa) {
    long[] ret = new long[sa.length];
    for (int i = 0; i < sa.length; i++) ret[i] = Long.parseLong(sa[i]);
    return ret;
  }
  static void mapLong(long[] ret, String[] sa) {
    for (int i = 0; i < sa.length; i++) ret[i] = Long.parseLong(sa[i]);
  }
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int answer = 0;
  int a = A;
  for (int i =0; i<(B-A+1); i++) {
    
    if ((a/10000 == a%10) && (a/1000%10 == a/10%10)) answer+=1;
    a++;
    }
  cout << answer << endl;
}

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

template<typename T>
using matrix = std::vector<std::vector<T>>;

bool gauss_jordan(matrix<int>& A, vector<int> const& b) {
    const int n = A.size();
    matrix<int> B(n, vector<int>(n + 1));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            B[i][j] = A[i][j];
        }
        B[i][n] = b[i];
    }

    int rank = 0;
    for(int i = 0; i < n; ++i) {
        int pivot = rank;
        for(int j = rank + 1; j < n; ++j) {
            if(B[j][i] == 1) {
                pivot = j;
                break;
            }
        }
        if(B[pivot][i] == 0) {
            continue;
        }
        swap(B[rank], B[pivot]);
        for(int j = rank + 1; j < n; ++j) {
            if(B[j][i] == 0) {
                continue;
            }
            for(int k = 0; k <= n; ++k) {
                B[j][k] ^= B[rank][k];
            }
        }
        rank++;
    }
    for(int i = rank; i < n; ++i) {
        if(B[i][n] == 1) {
            return false;
        }
    }
    return true;
}

int main() {
    int m, n, d;
    while(cin >> m >> n >> d, m) {
        const int D = m * n;
        matrix<int> A(D, vector<int>(D));
        vector<int> b(D);
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < m; ++j) {
                cin >> b[i * m + j];
            }
        }
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < m; ++j) {
                for(int i2 = 0; i2 < n; ++i2) {
                    for(int j2 = 0; j2 < m; ++j2) {
                        A[i * m + j][i2 * m + j2] = abs(i - i2) + abs(j - j2) == d;
                    }
                }
                A[i * m + j][i * m + j] = 1;
            }
        }

        cout << gauss_jordan(A, b) << endl;
    }
}


Measured memory_bytes: 5868
def main():
    N,Y=map(int,input().split())
    for i in range(N+1):#iは5000円札の枚数
        j=0
        if Y==10000*N-5000*i:
            print("{0} {1} {2}".format(N-i-j,i,j))
            return
        for j in range(N-i+1):#jは1000円札の枚数
            if Y==10000*N-5000*i-9000*j:
                print("{0} {1} {2}".format(N-i-j,i,j))
                return
    print("-1 -1 -1")

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
<?php


fscanf(STDIN, '%d', $count);
$max=1-10**9;
for($i=0;$i<$count;$i++) {
  fscanf(STDIN, '%d',$n);
  if($i===0){
    $min=$n;
  }else {
    if($n-$min>$max){
      $max=$n-$min;
    }
  }
  if($min>$n) {
    $min=$n;
  }
}
echo $max . PHP_EOL;


Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int n;
    cin >> n;
    rep(i, 1, n + 1) {
        int x = i;
        if (x % 3 == 0) cout << " " << x;
        else {
            while (x > 0) {
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3104
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left,int mid,int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value){
      A[k]=L[i++];
    }else{
      A[k]=R[j++];
    }
  }
}

void mergeSort(struct Card A[],int n,int left,int right){
  int mid;
  if(left+1 < right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[],int n,int p,int r){
  int i,j;
  struct Card t,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable=1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }
  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit!=B[i].suit)stable=0;
  }

  if(stable==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }
  return 0;
}



Measured memory_bytes: 4084
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 int S[1000];
  int top;
int isEmpty(){
  if(top==0){
  return 1;
  }
  else return 0;
}
void  push(int x){
  S[++top]=x;
}
int pop(){
  if(isEmpty()){
    fprintf(stderr,"Underflow\n");
  }
  else{
    
  top--;
  }
  return S[top+1];
}

int main (){
  int i,j;
  
  char s[100];
  top=0;
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      i=pop();
      j=pop();
      push(i+j);
    }
    else if(s[0]=='-'){
      j=pop();
      i=pop();
      push(i-j);
      }
    else if(s[0]=='*'){
      i=pop();
      j=pop();
      push(i*j);
    }
    else {
      push(atoi(s));
    
    }
  }
  printf("%d\n",pop());
  return 0;
}
    

Measured memory_bytes: 548
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int d[110][110];
int u[1010], v[1010], r[1010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i, 110) rep(j, 110) d[i][j] = INF/10;
    rep(i, 110) d[i][i] = 0;
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = d[b][a] = c;
        u[i] = a, v[i] = b, r[i] = c;
    }
    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i, m) {
        if(d[u[i]][v[i]] != r[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}


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

#define MAX 10000

bool isPrime(int n) {
	if (n == 2)
		return true;
	if (n < 2 || n % 2 == 0)
		return false;
	for (int i = 3; i <= sqrt(n); i += 2)
		if (n % i == 0)
			return false;
	return true;
}

int main() {
	int n, I, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> I;
		ans += isPrime(I) ? 1 : 0;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}

void get_divisors(lli n, vli &v){
    lli temp = lli(ceil( sqrt(n)));
    for(int i = 2; i < temp; i++){
        if(n % i == 0){
            v.pb(i);
            v.pb(n/i);
        }
    }
    if(temp * temp == n){
        v.pb(temp);
    }
    
}

int main(){
    
    fastio;
    
    lli N;
    cin >> N;
    if(N == 2){
        cout << 1 << endl;
        return 0;
    }
    set<lli> count;
    count.insert(N);

    vli v;
    v.pb(N - 1);
    get_divisors(N - 1, v);
    count.insert(all(v));

    v.clear();
    get_divisors(N, v);
    tr(v, div){
        lli tp = N;
        while(tp % div == 0){
            tp /= div;
        }
        if(tp % div == 1){
            count.insert(div);
        }
    }
    cout << sz(count) << endl;

    return 0;
}


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

int main()
{
	const int updn[] = {3, 0};
	
	int n;
	while (scanf("%d", &n), n){
		int res = 0;
		int state = 0;
		for (int i = 0; i < n; i++){
			string str;
			cin >> str;
			if (str == "lu") state += 1;
			if (str == "ru") state += 2;
			if (str == "ld") state -= 1;
			if (str == "rd") state -= 2;
			
			if (state == updn[res % 2]) res++;
		}
		
		cout << res << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1240
#include<stdio.h>
#include<string.h>
int main(){
    char s[4];
    scanf("%s",s);
    int f = 10*(s[0]-'0') + s[1]-'0';
    //printf("%d\n",f);
    int b = 10*(s[2]-'0') + s[3]-'0';
    if(f>=1 && f<=12 && b >=1 && b<=12){ //AMBIGUOUS
        printf("AMBIGUOUS\n");
    }
    else if(f>=0 && f <100 && b>=1 && b<=12 ){//YYMM
        printf("YYMM\n");
    }
    else if(f>=1 && f<=12 && b >=0 && b<100){//MMYY
        printf("MMYY\n");
    }
    else{
        printf("NA\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(){
  int n,m,max = 0;
  scanf("%d",&n);
  char s[n][20];
  for(int i = 0;i < n;i++){
    scanf("%s",&s[i]);
  }
  scanf("%d",&m);
  char t[m][20];
  for(int i = 0;i < m;i++){
    scanf("%s",&t[i]);
  }
  for(int i = 0;i < n;i++){
    int cnt = 0;
    for(int j = 0;j < n;j++){
      if(strcmp(s[i],s[j]) == 0){
        cnt++;
      }
    }
    for(int j = 0;j < m;j++){
      if(strcmp(s[i],t[j]) == 0){
        cnt--;
      }
    }
    if(max < cnt){
      max = cnt;
    }
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        vector<int> v(n);
        rep(i,n)cin>>v[i];
        sort(v.begin(),v.end());
        vector<int> v2(n-1);
        for(int i=0;i<n-1;i++){
            v2[i]=abs(v[i+1]-v[i]);
        }

        sort(v2.begin(),v2.end());
        cout<<v2[0]<<endl;

    }


    return 0;
}



Measured memory_bytes: 3160
# coding = SJIS
s = str(input())
lar = "BDEFGHIJKLMNOPQRSTUVWXYZ"
if s[0] != "A":
    print("WA")
    exit()
elif s[2:len(s)-1].count("C") != 1:
    print("WA")
    exit()
elif s[0:2].count("C") + s[-1].count("C") > 0:
    print("WA")
    exit()
kaz = 0
for i in lar:
    kaz += s.count(i)
if kaz > 0:
    print("WA")
    exit()
print("AC")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 100010;

vector <int> adj[MAX];

struct UnionFind {
    //number of parents(par[i] = i => root)
    vector <int> par;
    //rank of tree
    vector <int> rank;

    UnionFind(int n) : par(n), rank(n, 1) {
        //initialize
        rep(n, i) par[i] = i;
    }

    //find root (keiroasshuku at the same time)
    int root(int x){
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    //unite
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y]) swap(x, y);
        par[x] = y;
        if (rank[x] == rank[y]) rank[y]++;
    }

    //same tree?
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

void solve(void){

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

	if (N - 1 == M)
	{
		cout << 0 << endl;
		return;
	}

	if (N < 2*(N-M-1))
	{
		cout << "Impossible" << endl;
		return;
	}

	vector <int> as(N);
	rep(N, i) cin >> as[i];

	UnionFind uf(N);

	rep(M, i)
	{
		int x, y;
		cin >> x >> y;
		uf.unite(x, y);
	}

	set <int> vs;

	rep(N, i)
	{
		adj[uf.root(i)].pb(as[i]);
		vs.insert(uf.root(i));
	}

	ll ans = 0;

	vector <int> rest;

	for (int v : vs)
	{
		sort(all(adj[v]));
		ans += adj[v][0];
		rep((int)adj[v].size()-1, i) rest.pb(adj[v][i+1]);
	}

	sort(all(rest));

	int cnt = 2*(N-M-1) - (int)vs.size();

	rep(cnt, i)
	{
		ans += rest[i];
	}

	cout << ans << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, s.length() / 2)if(s[i]!=s[s.length()-1-i])cnt++;
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256