akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
 
 struct card{
           char gara;
           char kazu;
           };

 struct card card1[37];
 struct card card2[37];

 void bublle(struct card card1[],int n){
               int i,j;
               struct card t;
               for(i=0;i<n;i++){
                          for(j=n-1;j>i;j--){
                                   if(card1[j-1].kazu>card1[j].kazu){
                                                   t=card1[j-1];
                                                   card1[j-1]=card1[j];
                                                   card1[j]=t;
                                                   }
                                   }
                          }
               
               }

 void select(struct card card2[],int n){
           int i,j,min;
           struct card t;
           for(i=0;i<n;i++){
                     min=i;
                     for(j=i;j<n;j++){
                              if(card2[j].kazu<card2[min].kazu){
                                                        min=j;
                                                        }
                              }
                     if(min!=i){
                              t=card2[min];
                              card2[min]=card2[i];
                              card2[i]=t;
                              }
                    }
            
            }
 
 int main(){
         int i,j,n,x,flag;
         char c,ch;
         scanf("%d%c",&n,&ch);
         for(i=0;i<n;i++){
                    scanf("%c%c%c",&card1[i].gara,&card1[i].kazu,&ch);
                    }
        for(i=0;i<n;i++){card2[i]=card1[i];}

         bublle(card1,n);
         for(i=0;i<n;i++){
                   printf("%c%c%c",card1[i].gara,card1[i].kazu,(i==n-1)?'\n':' ');
                   }
         printf("Stable\n");

         select(card2,n);
         for(i=0;i<n;i++){
                   printf("%c%c%c",card2[i].gara,card2[i].kazu,(i==n-1)?'\n':' ');
                   }
         flag=1;
         for(i=0;i<n;i++){
                  if(card2[i].gara!=card1[i].gara){flag=0;break;}
                  }

         if(flag==1)printf("Stable\n");
         else printf("Not stable\n");

         return 0;
         }








Measured memory_bytes: 2068
def create(ans,l,r)
  if l == r
    return 0
  elsif r-l == 1
    ans[l][r] = 1
    return 1
  end

  mid = (l+r)/2
  level = 1 + [create(ans,l,mid), create(ans,mid+1,r)].max
  l.upto(r) do |i|
    (i+1).upto(r) do |j|
      ans[i][j] = level if ans[i][j] == -1
    end
  end
  return level
end

n = gets.to_i
ans = Array.new(n){[-1]*n}
create(ans,0,n-1)
(n-1).times do |i|
  puts ans[i][i+1,n-1].join(" ")
end

Measured memory_bytes: 4476
N = int(input())
S = input()
l = len(S)
word = ["a"]*l
for i in range(l):
  if ord(S[i]) + N <= 90:
    word[i] = chr(ord(S[i])+N)
  else:
    word[i] = chr(ord(S[i])+N-26)
print("".join(word))

Measured memory_bytes: 3064
#include <stdio.h>


int main() {

    int n,i,c=0;
    int a[50];
    scanf("%d",&n);
    for (i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    
    
    for (i=0; i<n; i++) {
        if (a[i] != i+1) {
            c++;
        }
    }
    if (c==0 || c==2) {
        printf("YES\n");
    }
    else
        printf("NO\n");
    
   
    return 0;
}


Measured memory_bytes: 1660
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
int main(){
//	ios::sync_with_stdio(false);
//	ifstream cin("data.txt");
//	freopen("data.txt", "r", stdin);
	int n, t, a, x, p = 1;
	cin >> n;
	cin >> t >> a;
	double c_min = 9999999;
	for(int i = 1; i <= n; i++){
		cin >> x;
		double cnt = t - x * 0.006;
		//cout << cnt << "cnt" << endl;
		if(abs(cnt - a ) < c_min){
			c_min = abs(cnt - a);
			p = i;
		}
	} 
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main()
{
    int a=0,b=0;
    cin>>a>>b;
    if(a<1 || b<1 || a>9 || b>9)
    cout<<"-1"<<endl;
    else
    {
        cout<<a*b<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main()
{
    int n ,i ,j ,s ,t;
    scanf("%d",&n);
    int a[n+1][3];
    for(i = 1;i < n;i++)
        scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
    for(j = 1;j < n;j++)
    {
        s = a[j][1] + a[j][0];
        for(i = j + 1;i < n;i++)
        {
            if(s >= a[i][1])
            {
                t = s - a[i][1];
                if(t % a[i][2])
                {
                    s = s + a[i][2] - t % a[i][2];
                }
                s += a[i][0];
            }
            else s = a[i][1] + a[i][0];
        }
        printf("%d\n",s);
    }
    printf("0");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> As(N);
    deque<int> Bs;
    REP(n,N) cin >> As[n];
    bool flag = false;
    for(auto a: As) {
        if (flag) {
            Bs.push_front(a);
        }
        else {
            Bs.push_back(a);
        }
        flag = !flag;
    }

    if (flag) reverse(ALL(Bs));
    REP(i, N) {
        if (i != 0) cout << " " << Bs[i];
        else cout << Bs[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3840
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

bool isRepeat(const string& s) {
  string t = s;
  reverse(begin(t), end(t));
  return s == t;
}

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

  const ll N = S.length();
  string sub_s1 = S.substr(0, (N - 1) / 2);
  string sub_s2 = S.substr((N + 3) / 2 - 1);
  string ans = "No";
  if (isRepeat(sub_s1) && isRepeat(sub_s2) && isRepeat(S)) {
    ans = "Yes";
  }

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


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)












int main() {
	ll a, b;
	cin >> a >> b;
	cout << max(a - 2 * b, 0LL) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    static int N,A,B,C;
    static int[] list;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String temp = sc.nextLine();

        String[] tempArr = temp.split(" ");
         N = Integer.parseInt(tempArr[0]);
         A = Integer.parseInt(tempArr[1]);
         B = Integer.parseInt(tempArr[2]);
         C = Integer.parseInt(tempArr[3]);

         list = new int[N];
         for (int i =0; i< N; i++) {
             list[i] = Integer.parseInt(sc.nextLine());
         }

        System.out.println(dfs(0,0,0,0));

    }

    public static int dfs(int depth,int length_a, int length_b, int length_c) {
        if (depth == N) {
            if (Math.min(length_a,Math.min(length_b,length_c)) > 0) {
                return Math.abs(length_a - A) + Math.abs(length_b - B) + Math.abs(length_c - C) - 30;
            } else {
                return 999999;
            }
        }
        int cost_a = dfs(depth + 1,length_a + list[depth],length_b,length_c) + 10;
        int cost_b = dfs(depth + 1,length_a,length_b + list[depth],length_c) + 10;
        int cost_c = dfs(depth + 1,length_a,length_b ,length_c + list[depth]) + 10;
        int cost_d = dfs(depth + 1,length_a,length_b,length_c);
        return Math.min(Math.min(cost_a,cost_b),Math.min(cost_c,cost_d));
    }

}

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


int main() {
  int a,b,t;
  cin>>a>>b>>t;
  int ans=(t/a)*b;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
#define FREE (-1)
#define NOT_FREE (1)

int row[8];
int col[8];
int dpos[15];
int dneg[15];
#define N (8)

bool dfs( int r ) {
    if ( r == N ) return true;
    if ( row[r] != FREE ) {		// ?????§???????????????
	return dfs( r + 1 );
    }
    else {
	for ( int c = 0; c < N; c++ ) {
	    if ( col[c] == NOT_FREE ||
		 dpos[r + c] == NOT_FREE ||
		 dneg[r - c + N - 1] == NOT_FREE ) continue;
	    row[r] = c;
	    col[c] = NOT_FREE;
	    dpos[r + c] = NOT_FREE;
	    dneg[r - c + N - 1] = NOT_FREE;
	    if ( dfs( r + 1 ) ) return true;
	    row[r] = FREE;
	    col[c] = FREE;
	    dpos[r + c] = FREE;
	    dneg[r - c + N - 1] = FREE;
	}

	return false;
    }
}

int main()
{
    int k;
    scanf("%d", &k);
    for ( int i = 0; i < N; i++ ) row[i] = col[i] = FREE;
    for ( int i = 0; i < 2 * N - 1; i++ ) dpos[i] = dneg[i] = FREE;
    for ( int i = 0; i < k; i++ ) {
	int r, c;
	scanf("%d %d", &r, &c);
	row[r] = c;
	col[c] = NOT_FREE;
	dpos[r + c] = NOT_FREE;
	dneg[r - c + N - 1] = NOT_FREE;
    }

    dfs( 0 );

    for ( int r = 0; r < N; r++ ) {
	for ( int c = 0; c < N; c++ ) {
	    if ( row[r] == c ) {
		printf("Q");
	    }
	    else {
		printf(".");
	    }
	}
	printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1004
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
//const ll mod=1e9+7;
const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll h,w,y,x;
  cin >> h >> w >> y >> x;
  mat dp(y+1,vec(x+1));
  dp[h][w]=1;
  for(ll i=h;i<=y;i++) {
    for(ll j=w;j<=x;j++) {
      if(i-h|j-w) {
        dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1)%mod+mod)%mod;
      }
    }
  }
  cout << dp[y][x] << endl;
}

Measured memory_bytes: 73592
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#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++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int K, S;
    cin >> K >> S;
    int cnt = 0;
    rep(i, K + 1)
    {
        rep(j, S - i + 1)
        {
            int x = j;
            int y = S - i - j;
            if (x <= K && y <= K)
            {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int n,cnt,e,f[N],a[N],id[N],w[N],siz[N],res[N],head[N],link[N],to[N];
bool vis[111111];
bool cmp(int x,int y){return a[x]<a[y];}
void add(int u,int v){to[++e]=v,link[e]=head[u],head[u]=e;}
void dfs1(int u,int dep){
	siz[u]=1,res[id[1]]+=dep;
	for(int i=head[u];i;i=link[i])if(to[i]!=f[u])dfs1(to[i],dep+1),siz[u]+=siz[to[i]];
}
void dfs2(int u){for(int i=head[u];i;i=link[i])if(to[i]!=f[u])res[to[i]]=res[u]+n-2*siz[to[i]],dfs2(to[i]);}
signed main(){
	scanf("%lld",&n),w[0]=-LLONG_MAX;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),id[i]=i,w[i]=a[i],siz[i]=1;
	sort(id+1,id+n+1,cmp),sort(w+1,w+n+1);
	for(int i=n;i>1;i--){
		int x=2*siz[id[i]]-n+a[id[i]],pos=lower_bound(w+1,w+n+1,x)-w;
		if(w[pos]!=x||n-2*siz[id[i]]<=0){printf("-1");return 0;}
		add(id[pos],id[i]),siz[id[pos]]+=siz[id[i]],f[id[i]]=id[pos];
	}
	dfs1(id[1],0),dfs2(id[1]);
	for(int i=1;i<=n;i++)if(a[i]!=res[i]){printf("-1");return 0;}
	for(int i=2;i<=n;i++)printf("%lld %lld\n",f[id[i]],id[i]);
}


Measured memory_bytes: 9984
import java.io.*;
import java.util.*;


//I have to use hashset
public class Main{
    public static void main(String[] args)throws IOException{
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //String str;
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        
        HashSet<String> d = new HashSet<String>();
        for(int i=0;i<n;i++){
            String temp = sc.next();
            String str = sc.next();
            if(temp.equals("insert")){
                d.add(str);
            }else if(temp.equals("find")){
                if(d.contains(str)){
                    System.out.println("yes");
                }else{
                    System.out.println("no");
                }
            }
        }

    }    
}


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

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

    int ans = 0;
    int x = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string s;
  getline(cin, s);
  for (char& c : s) {
    c = toupper(c);
  }
  cout << s << '\n';
}


Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int x;
	cin >> x;
	
	if( x >= 400 && x <= 599 ) cout << 8 << endl;
	else if( x >= 600 && x <= 799 ) cout << 7 << endl;
	else if( x >= 800 && x <= 999 ) cout << 6 << endl; 
	else if( x >= 1000 && x <= 1199 ) cout << 5 << endl; 
	else if( x >= 1200 && x <= 1399 ) cout << 4 << endl; 
	else if( x >= 1400 && x <= 1599 ) cout << 3 << endl; 
	else if( x >= 1600 && x <= 1799 ) cout << 2 << endl; 
	else if( x >= 1800 && x <= 1999 ) cout << 1 << endl; 
	
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	string s;
	cin >>s;
	if(s[2]==s[3] && s[4]==s[5])
		cout << "Yes";
	else 
		cout << "No";
	return 0;
}

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

int grundy(int n, int k) {
	if (n % k == 0) return n / k;
	int a = n / k;
	int b = n % k;
	return grundy(n - ((b + a) / (a + 1)) * (a + 1), k);
}

int main() {
	int n, a, k, i;
	cin >> n;
	
	int x = 0;
	for (i = 0; i < n; i++) {
		cin >> a >> k;
		x ^= grundy(a, k);
	}
	if (x == 0) cout << "Aoki" << endl;
	else cout << "Takahashi" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  string S;
  getline(cin, S);
  if(S == "SUN")
    cout << 7 << endl;
  else if(S == "MON")
    cout << 6 << endl;
  else if(S == "TUE")
    cout << 5 << endl;
  else if(S == "WED")
    cout << 4 << endl;
  else if(S == "THU")
    cout << 3 << endl;
  else if(S == "FRI")
    cout << 2 << endl;
  else if(S == "SAT")
    cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define EPS  1e-10//sample:if((double)>=(double)+EPS)
#define CLR(a) memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)  cerr << #x << " = " << (x) << endl;//debug
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);
using namespace std;

struct node {
  int id,parent,left,right;
};
typedef struct node *bint;
struct node T[10000];
void preperse(int u){
  if(u==-1)return;
  printf(" %d",u);
  preperse(T[u].left);
  preperse(T[u].right);
}
void inperse(int u){
  if(u==-1)return;
  inperse(T[u].left);
  printf(" %d",u);
  inperse(T[u].right);
}
void postperse(int u){
  if(u==-1)return;
  postperse(T[u].left);
  postperse(T[u].right);
  printf(" %d",u);
}

int main(){
  int n,id,l,r;
  cin>>n;
  for(int i=0;i<10000;i++)T[i].parent=-1;
  for(int i=0;i<n;i++){
    cin>>id>>l>>r;
    T[id].left=l;
    T[id].right=r;
    if(l!=-1)T[l].parent=id;
    if(r!=-1)T[r].parent=id;
  }
  int root;
  for(int i=0;i<n;i++)if(T[i].parent==-1)root=i;

  cout<<"Preorder"<<endl;
  preperse(root);
  cout<<endl<<"Inorder"<<endl;
  inperse(root);
  cout<<endl<<"Postorder"<<endl;
  postperse(root);
  cout<<endl;

  return 0;
}


Measured memory_bytes: 3392
import java.util.*; 
import java.io.*;

public class Main {
	static int inDegree[] = new int[100005]; 
	static boolean visited[] = new boolean[100005]; 
	static int dist[] = new int[100005]; 
	static ArrayList<Integer> g[] = new ArrayList[100005];
	public static void dfs(int a) {
		visited[a] = true; 
		for(Integer i : g[a]) {
			dist[i] = Math.max(dist[i], 1 + dist[a]);
			inDegree[i]--; 
			if(inDegree[i] == 0) {
				dfs(i); 
			}
		}
	}
	public static void solve(InputReader in) {
		int n = in.readInt();
		int m = in.readInt();
		 
		for(int i = 0; i<=n; i++) {
			g[i] = new ArrayList<Integer>();
		}
		
		for(int i = 0; i<m; i++) {
			int x = in.readInt(); int y = in.readInt(); 
			g[x].add(y); 
			inDegree[y]++; 
		}
		
		for(int i = 1; i<=n; i++) {
			if(!visited[i] && inDegree[i] == 0) {
				dfs(i); 
			}
		}
		int ans = -1;
		for(int i = 1; i<=n; i++) {
			ans = Math.max(ans, dist[i]); 
		}
		System.out.println(ans); 
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		int t = 1;
		while (t-- > 0)
			solve(in);
	}
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
     
     public String next() {
		return readString();
	}
    
     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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

typedef long long ll;

using namespace std;
const int INF = 1e9 + 5;

int main()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for(int &i : h)
	{
		cin >> i;
	}
	vector<int> dp(n,INF);
	dp[0] = 0;
	for(int i = 0 ; i < n ; i++)
	{
		for (int j : {i+1,i+2})
		{
			if (j < n)
				dp[j] = min(dp[j],dp[i] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n-1];
}


Measured memory_bytes: 3988
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, m;
vector<pair<int, int>> vec[55];
int d[55];
int p[55];
int g[55];
int cnt[25];
int ans;
int beki[55];

void dfs(int v, int pp, int k) {
	for (int i = 0; i < (int)vec[v].size(); i++) {
		if (vec[v][i].first == pp)continue;
		p[vec[v][i].first] = vec[v][i].second;
		d[vec[v][i].first] = k + 1;
		g[vec[v][i].first] = v;
		dfs(vec[v][i].first, v, k + 1);
	}
}

signed main() {
	beki[0] = 1;
	for (int i = 1; i <= 50; i++)beki[i] = beki[i - 1] * 2;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int a, b; cin >> a >> b;
		vec[a].push_back(make_pair(b, i));
		vec[b].push_back(make_pair(a, i));
	}
	dfs(1, 0, 0);
	cin >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		while (d[a] < d[b]) {
			cnt[i] += beki[p[b]];
			b = g[b];
		}
		while (d[a] > d[b]) {
			cnt[i] += beki[p[a]];
			a = g[a];
		}
		while (a != b) {
			cnt[i] += beki[p[b]];
			cnt[i] += beki[p[a]];
			b = g[b];
			a = g[a];
		}
	}
	for (int i = 0; i < beki[m]; i++) {
		int cnt2 = 0, cnt3 = 0;
		for (int j = 0; j < m; j++)if (i&beki[j]) {
			cnt2 |= cnt[j];
			cnt3++;
		}
		int cnt4 = 0;
		for (int j = 0; j < n - 1; j++)if (cnt2&beki[j])cnt4++;
		if (cnt3 % 2)ans -= beki[n - 1 - cnt4];
		else ans += beki[n - 1 - cnt4];
	}
	cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  long long ans = 1LL;
  long long maxNum = pow(10, 18);
  vector<long long> nums(N);
  for (int i = 0; i < N; i++) {
    cin >> nums[i];
  }
  sort(nums.begin(),nums.end());
  if(nums[0] == 0){
    cout << 0 << endl;
    return 0;
  }else{
    for(int i = 0; i < (int)nums.size(); i++) {
      if(ans > maxNum/nums[i]){
        cout << -1 << endl;
        return 0;
      }else ans *= nums[i];
    }
    cout << ans << endl;
    return 0;
  }
}

Measured memory_bytes: 4020
n = int(input())
V = map(int, input().split())

odd = []
even = []
for i, v in enumerate(V):
    if i % 2 == 0:
        odd.append(v)
    else:
        even.append(v)
num_odd = {}
for v in odd:
    if v in num_odd:
        num_odd[v] += 1
    else:
        num_odd[v] = 1
num_even = {}
for v in even:
    if v in num_even:
        num_even[v] += 1
    else:
        num_even[v] = 1
val_odd = sorted(num_odd.items(), key=lambda x:x[1])
val_even = sorted(num_even.items(), key=lambda x:x[1])
if len(val_odd) == 1 and len(val_even) == 1:
    if val_odd[0][0] == val_even[0][0]:
        # 全部同じ値 -> 半分変化させる
        print(n // 2)
    else:
        # すでに整ってる
        print(0)
else:
    # 奇数・偶数ともに必要なだけ変化させる
    if val_odd[-1][0] != val_even[-1][0]:
        # 最も多い値が違う場合はそれぞれその値を増やせばいい
        count_odd = n // 2 - val_even[-1][1]
        count_even = n // 2 - val_odd[-1][1]
        print(count_odd + count_even)
    else:
        # 同じ場合は、少ない方の第二頻出値を増やす
        c1 = n - val_odd[-1][1] - val_even[-2][1]
        c2 = n - val_odd[-2][1] - val_even[-1][1]
        print(min(c1, c2))


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

using namespace std;
using ll = long long;

int main(){
    int count = 0;
    vector<char> tmp(3), ans(3);
    for(int i = 0; i < 3; i++){
        cin >> tmp[i];
    }
    for(int i = 0; i < 3; i++){
        cin >> ans[i];
        if(tmp[i] == ans[i]) count++;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll k;
	int n;
	scanf("%lld%d",&k,&n);
	ll head;
	scanf("%lld",&head);
	ll head0=head;
	ll ans1=0;
	for(int i=2;i<=n;i++)
	{
		ll x;
		scanf("%lld",&x);
		ans1=max(ans1,x-head);
		head=x;
	}
	ans1=max(ans1,head0+k-head);
	printf("%lld\n",k-ans1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {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;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	ll n;
	cin>>n;
	double odd=0;
	for(int i=1;i<=n;i++){
		if(i%2==1)odd++;
	} 
	double sum=odd/n*1.0;
	cout<<sum<<endl;
}/*『你强归你强，我永不示弱』*/




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define  REP(i, n) for(int i=0; i<(n); ++i)
#define  ALL(obj) (obj).begin(), (obj).end()
#define ll long long
#define ul unsigned long

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int v[N];
  REP(i,N) cin >> v[i];
  sort(v,v+N);
  double max=(double)(v[0]+v[1])/2.0;
  FOR(i,2,N)
  {
    max = (max + (double)v[i])/2.0;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int n, a, b, c, ans = INT_MAX;
vector<int> l;

void dfs(int x, int i, int j, int k, int mp)
{
    if (x == n)
    {
        if (min(i, min(j, k)) > 0) {
            ans = min(ans, mp + abs(a - i) + abs(b - j) + abs(c - k) - 30);
        }
        return;
    }
    dfs(x + 1, i, j, k, mp);
    dfs(x + 1, i + l[x], j, k, mp+10);
    dfs(x + 1, i, j + l[x], k, mp+10);
    dfs(x + 1, i, j, k + l[x], mp+10);
}

int main()
{
    cin >> n >> a >> b >> c;
    l.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    dfs(0,0,0,0,0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <bits/stdc++.h>

using namespace std;


int H, W, D;
int a[310][310];
int b[90010],c[90010];
int d[90010];
int Q;
int l[100010],r[100010];
      

int main() {
    
    cin >> H >> W >> D;
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++)
      cin >> a[i][j];
     
  }
  cin >> Q;
  for(int i=0;i<Q;i++){
  cin >> l[i] >> r[i];
  }
  //ランダム配列の場合
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      b[a[i][j]]=i,c[a[i][j]]=j;
    }
  }
  
  for(int i=1;i<90000;i++){
  d[i+D] = d[i]+abs(b[i+D]-b[i])+abs(c[i+D]-c[i]);
  }
 
  
  for(int i=0;i<Q;i++){
  cout << d[r[i]]-d[l[i]] << endl;
  }
}
  
  
    
  
	


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

ll n;

vector<ll> t[1100];

bool search(ll now, ll num, bool used[]){
	//cout << now << " " << num << endl;
	bool res = false;
	REP(i, t[now].size()){
		if (used[t[now][i]])continue;
		if (t[now][i] == num)res = true;
		else{
			used[t[now][i]] = true;
			res |= search(t[now][i], num, used);
		}
	}
	return res;
}

int main(){
	bool ans = false;
	cin >> n;
	REP(i, n){
		ll a, b;
		string s;
		cin >> a >> s >> b;
		b += 100;
		if (s == "lock"){
			t[a].push_back(b);
		}
		else{
			t[b].push_back(a);
		}
	}
	REP(i, 100){
		bool used[1100] = {};
		ans |= search(i, i, used);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3216
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	int n, m, k;
	cin >> n >> m;
	if (n < m) {
		int swap;
		swap = n;
		n = m;
		m = swap;
	}
	k = m;
	while (k != 0) {
		m = k;
		k = n%m;
		n = m;
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 3076
# import itertools
# import math
# from functools import reduce
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

# if gcd_list(A) > 1:
#     print("not coprime")
#     exit()

# 高速素因数分解準備
#MAXN = 10**6+10
#sieve = [i for i in range(MAXN+1)]
#p = 2
#while p*p <= MAXN:
#    if sieve[p] == p:
#        for q in range(2*p, MAXN+1, p):
#            if sieve[q] == q:
#                sieve[q] = p
#    p += 1

l = make_divisors(M)

# print(l)

threshold = M / N

for i, d in enumerate(l):
    if threshold < d:
        print(l[i - 1])
        exit()

print(M)

Measured memory_bytes: 9040
n=int(input())
ls=list(map(int,input().split(" ")))

left=0
right=sum(ls)
diff=right-left
prev_diff=10**100
for i in ls:
    left+=i
    right-=i
    diff=abs(right-left)
    if diff>=prev_diff:
        break
    prev_diff=diff
print(prev_diff)


Measured memory_bytes: 26764
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int x, y;
    cin >> x >> y;
    bool ok = false;
    if(y%2==0 && y <= 4*x && y >= 2*x)ok = true;
    if(ok)cout << "Yes" << endl;
    if(!ok)cout << "No" << endl;
}

Measured memory_bytes: 3612
//Tue Dec 22 22:01:34 JST 2009
#include<set>
#include<iostream>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define mp make_pair
int dx[]={0,1,1,0,-1,-1};
int dy[]={-1,-1,0,1,1,0};
#define CONNECT true
#define UNCONNECT false
#define CANMOVE true
#define CANNOTMOVE false

class state{
public:
  int len;
  int x[8],y[8];
  int cnt;
  int path[8];
  bool is_connected(int me,int you){
    if ( x[me]==x[you]){
      if ( y[me]-1 == y[you] || y[me]+1 == y[you] || y[me]==y[you])return CONNECT;
    }else if ( x[me]+1 == x[you]){
      if (y[me] ==y[you] || y[me]-1==y[you])return CONNECT;
    }else if ( x[me]-1==x[you]){
      if (y[me] ==y[you] || y[me]+1 == y[you])return CONNECT;
    }

    return UNCONNECT;
  }

  bool can_good_pos(int cur){
    rep(i,cur-1){
      if ( is_connected(cur,i)==CONNECT)return false;//
    }
    if (cur==0 ||  is_connected(cur,cur-1)==CONNECT)return true;//
    return false;
  }
  
  void make_next(int now,queue<state>&Q,set<state>&S,bool flag,set<pair<int,int> > & NG){
    if ( now == len){
      if ( S.find((*this))==S.end()){
	cnt++;
	S.insert(*this);
	Q.push(*this);
	cnt--;
      }
      return;
    }

    //don't move
    
    if (can_good_pos(now) ){
      path[now]=-1;
      make_next(now+1,Q,S,CANMOVE,NG);
    }

    if ( flag == CANNOTMOVE)return;//

    rep(i,6){
      x[now]+=dx[i];
      y[now]+=dy[i];

      path[now]=i;

      if (NG.find(mp(x[now],y[now])) == NG.end() && can_good_pos(now)){
	make_next(now+1,Q,S,CANNOTMOVE,NG);//
      }
      x[now]-=dx[i];
      y[now]-=dy[i];
    }
        
  }
  
  bool operator<(const state & a)const{
    rep(i,len){
      if ( x[i]!=a.x[i])return x[i]<a.x[i];
      if ( y[i]!=a.y[i])return y[i]<a.y[i];
    }
    return false;
  }
  
};



int bfs(state ini,int dx,int dy,set<pair<int,int> > &NG){
  queue<state> Q;
  set<state> S;
  Q.push(ini);
  S.insert(ini);
  while(!Q.empty()){
    state now = Q.front();
    Q.pop();
if (80<now.cnt+(max(now.x[0],dx)-min(now.x[0],dy)+
max(now.y[0],dy)-min(now.y[0],dy))/3)continue;
    if ( now.x[0]==dx && now.y[0]==dy){
      return now.cnt;
    }
    now.make_next(0,Q,S,CANMOVE,NG);
  }
  return -1;
}


main(){
  int n,m,dx,dy;
  while(cin>>n && n){
    state ini;
    set<pair<int,int> > NG;
    
    ini.len=n;
    ini.cnt=0;
    rep(i,n)cin>>ini.x[i]>>ini.y[i];
    cin>>m;
    rep(i,m){
      int f,s;
      cin>>f>>s;
      NG.insert(mp(f,s));
    }
    cin>>dx>>dy;
    cout << bfs(ini,dx,dy,NG)<<endl;
  }
  return false;
}

Measured memory_bytes: 30000
using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
int main()
{
	int n;
	while(cin>>n&&n!=-1){
		int ans=1150;
		if(10<n)ans+=min(10,(n-10))*125;
		if(20<n)ans+=min(10,(n-20))*140;
		if(30<n)ans+=(n-30)*160;
		cout<<4280-ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
io = STDIN
n=io.gets.chomp.to_i
ar=io.gets.chomp.split.map(&:to_i)
cnt=0
delta=:mid
ar.each_cons(2) do |a,b|
  case delta
  when :mid
    if a==b
    elsif a<b
      cnt += 1
      delta = :up
    else
      cnt += 1
      delta = :down
    end
  when :up
    if a==b
    elsif a<b
    else
      delta = :mid
    end
  when :down
    if a==b
    elsif a<b
      delta = :mid
    else
    end
  end
end
cnt += 1 if delta == :mid
puts cnt

Measured memory_bytes: 9484
#include <bits/stdc++.h>
#define intt long long
#define INF INT_MAX
#define FAST_READ ios::sync_with_stdio(0);cin.tie(0);

using namespace std;

int main ()
{
    FAST_READ
    int  n,  m;
    cin >> n >> m;
    pair<int,int> a[m];
    for (int i=0;i<m;i++)cin>>a[i].second>>a[i].first;
    int ans = 0;
    sort(a,a+m);
    int mx = 0;
    for (int i=0;i<m;i++)
    {
        if ( a[i].second <= mx-1)continue;
        else
        {
            mx = a[i].first;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
ll gcd(ll a,ll b) {
	return !b?a:gcd(b,a%b);
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin>>n;
	ll ans=1;
	rep(i,1,n) {
		ll x;
		cin>>x;
		ans=ans/gcd(x,ans)*x;
	}
	cout<<ans<<'\n';
	return 0;
}



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

int main()
{
  int A,B,C,fg=0;
  cin>>A>>B>>C;
  if(A==5 && B==5 && C==7)
    fg=1;
  else if(A==5 && B==7 && C==5)
    fg=1;
  else if(A==7 && B==5 && C==5)
    fg=1;
  else
    fg=0;
  if(fg==1)
    cout<<"YES"<<'\n';
  else
    cout<<"NO"<<'\n';
}


Measured memory_bytes: 3640
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
collect = 0
for i in range(n):
    ret = c
    for j in range(m):
        ret += a[i][j] * b[j]
    if ret > 0:
        collect += 1
print(collect)

Measured memory_bytes: 3064
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_103_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 S      PIC X(100) VALUE SPACE.
    01 REDEFINES S.
        03 SC PIC X OCCURS 100.

    01 SLEN   PIC 9(3).

    01 T      PIC X(100) VALUE SPACE.
    01 REDEFINES T.
        05 TC PIC X OCCURS 100.

    01 i      PIC 9(3).
    01 j      PIC 9(3).
    01 flg    PIC 9(1).
    01 tmp    PIC X(1).
    01 bk     PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT S.
    ACCEPT T.

    COMPUTE SLEN = FUNCTION STORED-CHAR-LENGTH(S).

    MOVE ZERO TO flg.

    IF S = T THEN
        MOVE 1 TO flg
    ELSE
        PERFORM VARYING i FROM 1 BY 1 UNTIL SLEN <= i
            MOVE SC(1) TO bk
            PERFORM VARYING j FROM 1 BY 1 UNTIL SLEN <= j
                MOVE SC(j + 1) TO tmp
                MOVE bk TO SC(j + 1)
                MOVE tmp TO bk
            END-PERFORM
            MOVE bk TO SC(1)
            IF S = T THEN
                MOVE 1 TO flg
                EXIT PERFORM
            END-IF
        END-PERFORM
    END-IF.

    IF flg = 1 THEN
        DISPLAY "Yes"
    ELSE
        DISPLAY "No"
    END-IF.

    STOP RUN.


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long A, B;
  cin >> A >> B;
  bool tf = false;
  long long mid = A+B;
  long long ans = 0;
  if(mid%2 == 0) {
    tf = true;
    ans = mid/2;
  }
  if(tf){
    cout << ans << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

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

int main() {
  int a, b ,c ,d;
  cin >> a >> b >> c >>d;
  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" <<endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


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

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++) cin>>v[i];
  long sum=0;
  for(int i=1;i<n;i++){
    if(v[i]<v[i-1]){
      int p=v[i-1]-v[i];
      sum+=p;
      v[i]+=p;
    }
  }
  cout<<sum;
}

Measured memory_bytes: 4052
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    diff, rst = -1, 0
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

Measured memory_bytes: 9136
from collections import Counter

mod = (10 ** 9 + 7) ** 5
MAX = 2 * 10 ** 5 + 1 # これは変動するので注意

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n, r):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

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

counter = Counter(A)

mapping = {}
for k, v in counter.items():
    mapping[k] = nCr(v, 2)

all_sum = 0
for v in mapping.values():
    all_sum += v

memo = {}
for i in range(n):
    num = A[i]
    if num in memo:
        print(memo[num])
    else:
        t = counter[num]
        ans = all_sum - nCr(t, 2) + nCr(t - 1, 2)
        print(ans)
        memo[num] = ans



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

#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]); if(i!=n-1) cout << " ";} cout << endl;
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll A[1010], B[1010];
    map<ll,ll> mp_a, mp_b;
    cin >> N >> M;
    bool flg = true;
    rep(i,0,N){
        cin >> A[i];
        mp_a[A[i]]++;
        if(mp_a[A[i]] == 2) flg = false;
    }
    rep(i,0,M){
        cin >> B[i];
        mp_b[B[i]]++;
        if(mp_b[B[i]] == 2) flg = false;
    }
    sort(A,A+N);
    sort(B,B+M);
    // printa(A,N);
    // printa(B,M);
    ll ans = 1;
    ll cnt = 0;
    rrep(i,N*M,1){
        ll v1 = lower_bound(A, A+N, i) - A;
        ll v2 = lower_bound(B, B+M, i) - B;
        // print2("i=",i);
        // print2(v1,v2);
        if(v1 == N || v2 == M){
            flg = false;
            break;
        }
        ll alt = (N - v1) * (M - v2);
        // print(alt);
        alt -= cnt;
        if(alt < 0){
            flg = false;
            break;   
        }
        if(mp_a[i] == 1 && mp_b[i] == 1){
            ans *= 1;
            cnt++;
        }else if(mp_a[i] == 1){
            ans *= (M-v2);
            ans %= MOD;
            cnt++;

        }else if(mp_b[i] == 1){
            ans *= (N-v1);
            ans %= MOD;
            cnt++;

        }else{ 
            ans *= alt;
            ans %= MOD;
            cnt++;
        }
    }
    if(!flg){
        print(0);
    }else{
        print(ans % MOD);
    }
}


Measured memory_bytes: 125312
from itertools import accumulate
N = int(input())
A_list = list(map(int,input().split()))
B_list = A_list[::-1]
C_list = list(accumulate(B_list))
D_list = C_list[::-1]
cnt = 0
for i in range(1,N):
    cnt += (A_list[i-1] * D_list[i]) % (10**9 + 7)

    if cnt >= (10**9 + 7):
        cnt -= (10**9 + 7)
print(cnt)

Measured memory_bytes: 104904
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    int n = s.length();
    map <char, int> mp;
    REP(i,n) mp[s[i]]++;
    if (mp.size() != 2) {
        cout << "No" << endl;
        return 0;
    }

    for (auto &&e: mp) {
        if (e.second != 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 764
from fractions import gcd
n,x=map(int,input().split())
X=list(map(int,input().split()))

X=X+[x]
X.sort()
sa=[0]*n
for i in range(1,n+1):
  sa[i-1]=X[i]-X[i-1]
if len(sa)==1:
  print(sa[0])
else:
  ans=sa[0]
  for i in range(1,n):
    ans=gcd(ans,sa[i])
  print(ans)

Measured memory_bytes: 16300
#include <iostream>
using namespace std;
#define INF 1e9
#define MAX_E 500000
#define MAX_V 100000

struct edge {int u, v, cost;};
edge es[MAX_E];

int dis[MAX_V];
int V, E, r;

void bellman_ford(int s){
  for(int i = 0; i < V; i++) dis[i] = INF;
  dis[s] = 0;
  while(true){
    bool update = false;
    for(int i = 0; i < E; i++){
      edge e = es[i];
      if(dis[e.u] != INF && dis[e.v] > dis[e.u] + e.cost){
        dis[e.v] = dis[e.u] + e.cost;
        update = true;
      }
    }
    if(!update) break;
  }
}

int main(void){
  int s, t, d;
  cin >> V >> E >> r;
  for(int i = 0; i < E; i++){
    cin >> s >> t >> d;
    edge e;
    e.u = s; e.v = t; e.cost = d;
    es[i] = e;
  }
  bellman_ford(r);
  for(int i = 0; i < V; i++){
    if(dis[i] == INF) cout << "INF" << endl;
    else cout << dis[i] << endl;
  }
  return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a < b) swap(a,b);

    int ans = a--;
    if(a < b) swap(a,b);

    ans += a;

    cout << ans << endl;
}


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



int main() {
    int N;
    string S,T,U;
    cin>>S;
    N=S.size();
    N--;
    N/=2;
    rep(i,N){
        T.push_back(S.at(i));
    }
    rep(i,N){
        U.push_back(S.at(i+N+1));
    }
    bool j=true;
    if(T!=U){j=false;}
    reverse(U.begin(),U.end());
    if(T!=U){j=false;}
    if(j){
        cout<<"Yes"<<endl;
    }
    else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256