akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
  int vx,vy,x3,y3,x4,y4;

  vx = x2 - x1;
  vy = y2 - y1;

  x3 = x2 - vy;
  y3 = y2 + vx;

  x4 = x3 - vx;
  y4 = y3 - vy;

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()
X = int(S, 2)
pcx = S.count('1')
# ビット反転で1が0になる場合
pc1 = X % (pcx - 1) if pcx > 1 else 0
# ビット反転で0が1になる場合
pc2 = X % (pcx + 1)


def f(j):
    cnt = 0
    while j:
        j %= bin(j).count('1')
        cnt += 1
    return cnt


for i, y in enumerate(S):
    k = N - i - 1
    if y == "0":  # modを分配するときは、分配してからもう１回modを作用させれば良い
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)


Measured memory_bytes: 81520
// 2012/07/09 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		for(int i=0; i<n; i++){
			int pm, pe, pj;
			cin >> pm >> pe >> pj;

			if(pm==100||pe==100||pj==100){
				cout << 'A' << endl;
			}
			else if((pm+pe)/2>=90){
				cout << 'A' << endl;
			}
			else if((pm+pe+pj)/3>=80){
				cout << 'A' << endl;
			}
			else if((pm+pe+pj)/3>=70){
				cout << 'B' << endl;
			}
			else if((pm+pe+pj)/3>=50&&(pm>=80||pe>=80)){
				cout << 'B' << endl;
			}
			else{
				cout << 'C' << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
class Magic2
  def initialize(a, b, c, k)
    @a = a
    @b = b
    @c = c
    @k = k
  end

  def f(x, y, z)
    if x < y
      [y, z]
    else
      f(x, y * 2, z + 1)
    end
  end
  
  def solve
    b2, k2 = f(@a, @b, 0)
    _, k3 = f(b2, @c, k2)
    
    if @k >= k3
      "Yes"
    else
      "No"
    end
  end
end

def run
  a, b, c = gets.scan(/\d+/).map(&:to_i)
  k = gets.chomp.to_i
  puts Magic2.new(a, b, c, k).solve
end

run


Measured memory_bytes: 14280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

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

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

    vector<vector<int>> cnt(N + 3, vector<int>(N + 3));
    for (int i = 0; i < M; ++i) {
        int l, r;
        cin >> l >> r;
        cnt[l][r]++;
    }

    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j < N; ++j)
            cnt[i][j + 1] += cnt[i][j];
    }

    for (int i = 0; i < Q; ++i) {
        int p, q, ans = 0;
        cin >> p >> q;
        for (int j = p; j <= q; ++j)
            ans += cnt[j][q] - cnt[j][j - 1];
        cout << ans << '\n';
    }

    return 0;
}


Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static string S;
    static void Main()
    {
        S = Console.ReadLine();
      Modular[,] amarisave=new Modular[S.Length,13];//その桁の余りが０の場合～１２の場合について，ケース数をセーブ
for(int i=0;i<S.Length;i++){for(int j=0;j<13;j++){amarisave[i,j]=new Modular(0);}}
      for(int i=0;i<S.Length;i++)
{
      
  //上から一桁ずつやっていく。     
if(S[i]=='?'){
if(i>0){
  for(int l=0;l<10;l++){
              for(int j=0;j<13;j++){
              for(int k=0;k<13;k++){
if((j*10+l)%13==k){amarisave[i,k]+=amarisave[i-1,j];}
              }
              }
  }
}
  else
  {
  for(int j=0;j<10;j++){amarisave[i,j]=1;}
  }
}
        else{
          if(i>0){
            for(int j=0;j<13;j++){
              for(int k=0;k<13;k++){
if((j*10+S[i]-'0')%13==k){amarisave[i,k]=amarisave[i-1,j];}
              }
              }
          }else{amarisave[0,S[i]-'0']=1;}
        }
}

        Console.WriteLine(((int)amarisave[S.Length-1,5]).ToString());
        
    }

 


}

class Modular
{
    private const int M = 1000000007;
    private long value;
    public Modular(long value) { this.value = value; }
    public static implicit operator Modular(long a)
    {
        var m = a % M;
        return new Modular((m < 0) ? m + M : m);
    }
    public static Modular operator +(Modular a, Modular b)
    {
        return a.value + b.value;
    }
    public static Modular operator -(Modular a, Modular b)
    {
        return a.value - b.value;
    }
    public static Modular operator *(Modular a, Modular b)
    {
        return a.value * b.value;
    }
    private static Modular Pow(Modular a, int n)
    {
        switch (n)
        {
        case 0:
            return 1;
        case 1:
            return a;
        default:
            var p = Pow(a, n / 2);
            return p * p * Pow(a, n % 2);
        }
    }
    public static Modular operator /(Modular a, Modular b)
    {
        return a * Pow(b, M - 2);
    }
    private static readonly List<int> facs = new List<int> { 1 };
    private static Modular Fac(int n)
    {
        for (int i = facs.Count; i <= n; ++i)
        {
            facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
        }
        return facs[n];
    }
    public static Modular Ncr(int n, int r)
    {
        return (n < r)  ? 0
             : (n == r) ? 1
                        : Fac(n) / (Fac(r) * Fac(n - r));
    }
    public static explicit operator int(Modular a)
    {
        return (int)a.value;
    }
}


Measured memory_bytes: 75416
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

    int n ;
    long double d ;
    cin >> n >> d;

    int x[n],y[n] ;
    int ans = 0 ;
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i] ;
    }

    for(int i=0;i<n;i++){
        long double tmpa = pow(x[i],2) ;
        long double tmpb = pow(y[i],2) ;
        long double dis = sqrt(tmpa+tmpb) ;
         //cout << dis << endl;
        if(dis<=d) ans++ ;
    }

    cout << ans << endl;

    return 0 ;
}

Measured memory_bytes: 5320
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
#define FL(i,a,b) for(int i = a;i<b;i++)
typedef vector<int> vi;

const int inf = numeric_limits<int>::max();


int main(){
    long int n;
    cin>>n;
    int ip[n][3];
    for(long int i = 0;i<n;i++){
        FL(j,0,3){
            cin>>ip[i][j];
        }
    }
    int happi[n][3] = { };
    happi[0][0] = ip[0][0];
    happi[0][1] = ip[0][1];
    happi[0][2] = ip[0][2];

    for(long int i =1;i<n;i++){
        FL(j,0,3){
            if(j==0){
                happi[i][j] = max(happi[i-1][1],happi[i-1][2]);
            }
            else if(j==1){
                happi[i][j] = max(happi[i-1][0],happi[i-1][2]);
            }
            else if(j==2){
                happi[i][j] = max(happi[i-1][1],happi[i-1][0]);
            }
            happi[i][j] += ip[i][j];
        }
    }
    int maxie = 0;
    FL(i,0,3){
        maxie = max(maxie,happi[n-1][i]);
    }
    cout<<maxie;
    
    
}

















Measured memory_bytes: 2560
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
	    while(s.hasNext()){
	    	int n=s.nextInt();
	    	int count=0;
	    	for(int i=0;i<10;i++)for(int j=0;j<10;j++)for(int k=0;k<10;k++)for(int l=0;l<10;l++)if(i+j+k+l==n)count++;
	    	System.out.println(count);
	    }
	}    	
}

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

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

using namespace std;

int main(void)
{
	ui N{ 0 };
	ui A{ 0 };
	ui B{ 0 };
	ui C{ 0 };
	ui D{ 0 };
	string str{ 0 };

	cin >> N >> A >> B >> C >> D >> str;

	str = "#" + str;
	bool result{ true };

	// A番目～C番目及び、
	// B番目～D番目までの部分文字列に
	// "##"が存在するとき、到達不可能
	{
		string sec_ac = str.substr(A, (C - A) + 1);
		result &= (sec_ac.find("##", 0) == sec_ac.npos);
	}
	{
		string sec_bd = str.substr(B, (D - B) + 1);
		result &= (sec_bd.find("##", 0) == sec_bd.npos);
	}

	if (result && C > D)
	{
		// B - 1番目～D + 1番目までの部分文字列に
		// "..."が存在する必要がある
		string sec = str.substr(B - 1, ((D + 1) - (B - 1)) + 1);
		result &= (sec.find("...", 0) != sec.npos);
	}
	
	auto ans = result ? "Yes" : "No";

	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 772
using System;
using System.Linq;
using System.Collections.Generic;
 
class MainClass {
  public static void Main (string[] args) {
    var list = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    var N = list[0];
    var K = list[1];
 
    var dic = new Dictionary<long, long>();
 
    for(var i = 0; i < N; i++){
      var temp = Console.ReadLine().Split(' ').Select(long.Parse);
      if(dic.ContainsKey(temp.ElementAt(0))){
        dic[temp.ElementAt(0)] += temp.ElementAt(1);
      }else{
        dic.Add(temp.ElementAt(0), temp.ElementAt(1));
      }
     
    }
    var a = dic.Select(x => x).OrderBy(x => x.Key).ToList();
    var sum = (long)0;
    for(var i = 0; i < N; i++){
        sum += a[i].Value;
        if(sum >= K){
          Console.WriteLine(a[i].Key);
          return;
        }
    }
 
  }
}

Measured memory_bytes: 25156
const l = {
  'hon': [2, 4, 5, 7, 9],
  'pon': [0, 1, 6, 8],
  'bon': [3]
}

const processData = (lines) => {
  const n = lines[0]
  const t = +n[n.length -1]
  for (let p in l) {
    if (l[p].includes(t)) {
      console.log(p)
      break
    }
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})


Measured memory_bytes: 29876
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef struct {
	int m[6];
} Dice;

Dice d, e;
int q, up, fr;
string s = "NNENN", w = "HHHH";

void roll(char c, Dice *d) {
	switch (c) {
	case 'N':
		swap(d->m[0], d->m[1]);
		swap(d->m[1], d->m[5]);
		swap(d->m[5], d->m[4]);
		break;
	case 'S':
		swap(d->m[0], d->m[4]);
		swap(d->m[4], d->m[5]);
		swap(d->m[5], d->m[1]);
		break;
	case 'E':
		swap(d->m[0], d->m[3]);
		swap(d->m[3], d->m[5]);
		swap(d->m[5], d->m[2]);
		break;
	case 'W':
		swap(d->m[0], d->m[2]);
		swap(d->m[2], d->m[5]);
		swap(d->m[5], d->m[3]);
		break;
	case 'H':
		swap(d->m[1], d->m[2]);
		swap(d->m[2], d->m[4]);
		swap(d->m[4], d->m[3]);
		break;
	}
}
void solve() {
	e = d;
	for (unsigned i = 0; i < s.size() + 1; i++) {
		for (unsigned j = 0; j < w.size(); j++) {
			if (e.m[0] == up && e.m[1] == fr) {
				cout << e.m[2] << endl;
				return;
			}
			roll(w[j], &e);
		}
		if(i < s.size())roll(s[i], &e);
	}
}
int main() {
	for (int i = 0; i < 6; i++) cin >> d.m[i];
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> up >> fr;
		solve();
	}
}


Measured memory_bytes: 3160
//Created by Aminul on 8/2/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt(), q = in.nextInt();
        int arr[] = new int[n + 1];
        int last[] = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            int x = in.nextInt();
            arr[i] = last[x];
            last[x] = i;
        }

        ArrayDeque<int[]> queries[] = genDQ(n + 1);
        for (int i = 0; i < q; i++) {
            int l = in.nextInt(), r = in.nextInt();

            queries[r].add(new int[]{i, l, +1});
            queries[l - 1].add(new int[]{i, l, -1});
        }

        BinaryIndexTree bit = new BinaryIndexTree(n + 10);
        int[] res = new int[q];
        for (int i = 1; i <= n; i++) {
            bit.add(arr[i], +1);
            for (int qry[] : queries[i]) {
                res[qry[0]] += qry[2] * bit.sum(qry[1] - 1);
            }
        }

        for (int ans : res) {
            pw.println(ans);
        }

        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static <T> ArrayDeque<T>[] genDQ(int n) {
        ArrayDeque<T> list[] = new ArrayDeque[n];
        for (int i = 0; i < n; i++) list[i] = new ArrayDeque<T>();
        return list;
    }

    static class BinaryIndexTree {
        public int bit[], n, offset = 5;

        public BinaryIndexTree(int N) {
            n = N;
            bit = new int[n + offset + 10];
        }

        public void add(int index, int value) {
            index += offset;
            for (; index < n; index = index + (index & -index)) {
                bit[index] += value;
            }
        }

        public int sum(int index) {
            index += offset;
            int sum = 0;
            for (; index > 0; index = index - (index & -index)) {
                sum += bit[index];
            }
            return sum;
        }

        public int query(int i, int j) {
            return sum(j) - sum(i - 1);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() throws Exception {
            while (tokenizer == null || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(reader.readLine());
            return tokenizer.nextToken();
        }

        public int nextInt() throws Exception {
            return Integer.parseInt(next());
        }

    }
}

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

using namespace std;

const int maxn=1e5+5;

int a[maxn]; 

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
	} 
	
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ans+=a[i]*a[j];
		}
	}
	printf("%d",ans);
	return 0;
}

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

using namespace std;

int main(){
  double xa,ya,xb,yb,xc,yc,xd,yd;
  while(cin>>xa>>ya>>xb>>yb>>xc>>yc>>xd>>yd){
    if(fabs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1e-10) cout<<"YES";
    else cout<<"NO";
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>
#include <vector>
#include <algorithm>

#define int long long

using namespace std;

int ans, n;

vector < int > a;

void mi( int i, int mn, vector <int> a );


void pl( int i, int mn, vector <int> a )
{
    if( i == a.size() )
    {
        ans = max( ans, mn );
        return ;
    }
    mn = min( min(mn,  24 - abs(a[i] - a[i - 1]) ), min( abs( a[i] - a[i - 1]), abs(a[i] - a[i - 2] ) ) );
    if( mn < ans )
        return ;
    mi(i + 1, mn, a );
    pl(i + 1, mn, a );
}
void mi( int i, int mn, vector <int> a )
{
    if( i == a.size() )
    {
        ans = max( ans, mn );
        return ;
    }
    a[i] = 24 - a[i];
    mn = min( min(mn, abs(a[i] - a[i - 2]) ), min(abs(a[i] - a[i - 1]), 24 - abs(a[i] - a[i - 1])) );
    if( mn < ans )
        return ;
    pl(i + 1, mn, a );
    mi(i + 1, mn, a );
}

main ()
{
    int t = 0;
    scanf("%I64d", &n);
    if( n > 24 )
        t = 1;
    for( int i = 1; i <= n; i++ )
    {
        int q;
        scanf("%I64d", &q);
        a.push_back(q);
    }
    if( t == 1 )
    {
        puts("0");
        return 0;
    }
    sort( a.begin(), a.end() );
    pl(1, a[0], a);
    mi(1, a[0], a);
    printf("%I64d", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")

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

	int x;
	cin >> x;

	if (x < 1200)
	{
		cout << "ABC";
	}
	else
	{
		cout << "ARC";
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

long int  count(int n, long int k) {
  if (n < 0 || k <= 0) {
    return 0;
  }
  if (k*2 > (1ull<<(n+2))-3) {
    return (1ull<<n) + count(n-1, k-(1ull<<(n+1))+1);
  } else {
    return count(n-1, k-1);
  }
}

int main() {
  int n;
  long int x;
  scanf("%d%ld", &n, &x);
  long int cnt;
  cnt = count(n, x);
  printf("%ld\n", cnt);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[100000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	int m=a[n-1];
	int max=n-1,mi=0,mid;
	while(max-mi>=2){
		mid=(max+mi+1)/2;
		if(m/2>=a[mid]){
			mi=mid;
		}
		else{
			max=mid;
		}
	}
	if(a[max]-(double)m/2>=(double)m/2-a[mi]){
		cout<<m<<" "<<a[mi]<<endl;
		return 0;
	}
	cout<<m<<" "<<a[max]<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
int C;
int U[100000], R[100000];
vector<int> G[100000];
int V[100000];

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
  R[y] = 0;
}

bool same(int x, int y) {
  return find(x) == find(y);
}

int dfs(int x, int p, int l) {
  if (V[x] != -1) return V[x] ^ l;
  V[x] = l;

  int s = -1;
  for (int t : G[x]) {
    if (t == p) continue;
    s = max(s, dfs(t, x, l^1));
  }
  return s;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  for (int i=0; i<N; i++) U[i] = i, R[i] = 1, V[i] = -1;
  rep(i, M) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
    unite(u, v);
  }
  long long s = 0;
  int a = 0, b = 0, c = 0;
  rep(i, N) {
    int n = R[i];
    if (n == 0) continue;
    if (n == 1) c++;
    else {
      int l = dfs(i, -1, 0);
      if (l == 1) b++;
      else a++;
    }
  }
  s += 1LL*a*a;
  s += 1LL*(a+b)*(a+b);
  s += 2LL*N*c - (1LL*c*c);
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 11648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// const ll INF = 1e18;
// const ll MOD = 1e9+7;
const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll N;

int Main() {
    cin >> N;
    const double PI = acos(-1);
    cout <<  N* PI* 2 << endl;
    return 0;
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main() {
	int N;
	cin >> N;
	vector<vector<int>> V(N, vector<int>(2));
	double sum = 0;
	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		V[i][0] = x;
		V[i][1] = y;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			sum += sqrt(pow(V[j][0] - V[i][0], 2) + pow(V[j][1] - V[i][1], 2));
		}
	}
	printf("%6f", sum / N);
}

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

int main() {
  vector<string> v = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  string S;
  cin >> S;
  if (S == "SUN") {
    cout << 7 << endl;
    return 0;
  }
  
  int x;
  for (int i = 0; i < 7; i++) {
    if (S == v.at(i)) {
      x = i;
      break;
    }
  }
  
  cout << 7 - x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
int main(void){
    ll n,k;
    cin>>n>>k;
    ll a[n],c[n];
    rep(0,i,n)c[i]=-1;
    rep(0,i,n){
        cin>>a[i];
        a[i]--;
    }
    ll x=0;
    bool t=true;
    rep(0,i,k){
        if(c[x]==-1&&t){
            c[x]=i;
            x=a[x];
        }else if(t){
            ll ro=i-c[x];
            i=i+(k-1-i)/ro*ro;
            //cout<<i<<endl;
            t=false;
        }
        if(!t){
            x=a[x];
        }
    }
    cout<<x+1<<endl;
}

Measured memory_bytes: 6768
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

#define T true
#define F false
// T:left, F:right
//             a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
bool keys[] = {T,T,T,T,T,T,T,F,F,F,F,F,F,F,F,F,T,T,T,T,F,T,T,T,F,T};

int main(){
  bool last;
  bool first=true;
  int res=0;
  while(true){
    char c;
    scanf("%c", &c);
    
    if(c=='#'){
      break;
    } else if(first){
      res=0;
      first=false;
      last=keys[c-'a'];
    } else if(c=='\n'){
      cout << res << endl;
      first=true;
      res=0;
    } else{
      if(keys[c-'a']!=last){
	last = !last;
	res++;
      }
    }
  }


}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

from functools import lru_cache


def main(): 
    s = II()

    print('ARC' if s >= 1200 else 'ABC')




main()

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define di deque<ll>
#define vvi vector<vi>
#define vs vector<string>
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define fs first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
#define mxn (ll)1e5
#define INF = 1e18L + 5;
int main(){
    string s,t;
    cin>>s>>t;
    string f = t.substr(0,t.length()-1);
    if(s==f){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}

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

const int INF = 2100100100;
const int MOD = 1e9 + 7;

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main() {
    int N;
    cin >> N;
    int ans = 0;
    REP(i, N + 1) {
        vector<long long> divs = divisor(i);
        if (i % 2 == 1 && divs.size() == 8) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int;  // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n) {
  int ret = 1;
  for (int i = 1; i < n + 1; ++i) {
    ret = ret * i;
  }
  return ret;
}

/* 最大公約数 */
template <typename T>
T gcd(T x, T y) { return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>
T lcm_n(vector<T> &numbers) {
  T l;
  l = numbers[0];
  for (int i = 1; i < numbers.size(); ++i) {
    l = lcm(l, numbers[i]);
  }
  return l;
}

/*
 * DP向け
 */
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;
}



int main() {
  ll a, b;
  cin >> a >> b;

  cout << a * b << endl;

  return 0;
}


Measured memory_bytes: 3644
# -*- coding:utf-8 -*-

def solve():
    import math

    N, K = list(map(int, input().split()))
    As = list(map(int, input().split()))

    left, right = 1, 10**9
    while left != right:
        mid = (left+right)//2
        cut = 0

        for a in As:
            if a/mid > 1: cut += math.ceil(a/mid) - 1

        if cut <= K:
            # 切って良い回数を満たしている
            if left+1 == right:
                print(left)
                return
            right = mid
        else:
            # 切って良い回数を満たしていない
            if left+1 == right:
                print(right)
                return
            left = mid



if __name__ == "__main__":
    solve()


Measured memory_bytes: 31428
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<long> A(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	long ans = 0;
	if(N % 2){
		long ans1 = 0, ans2 = 0;
		for(int i=0;i<N / 2;i++){
			ans1 -= 2 * A[i];
		}
		ans1 += A[N / 2];
		ans1 += A[N / 2 + 1];
		for(int i=N / 2+2;i<N;i++){
			ans1 += 2 * A[i];
		}
		for(int i=0;i<N / 2 - 1;i++){
			ans2 -= 2 * A[i];
		}
		ans2 -= A[N / 2 - 1];
		ans2 -= A[N / 2];
		for(int i=N / 2+1;i<N;i++){
			ans2 += 2 * A[i];
		}
		ans = max(ans1, ans2);
	}
	else{
		for(int i=0;i<N / 2 - 1;i++){
			ans -= 2 * A[i];
		}
		ans -= A[N / 2 - 1];
		ans += A[N / 2];
		for(int i=N / 2+1;i<N;i++){
			ans += 2 * A[i];
		}
	}
	cout << ans << endl;
}

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

int main(int argc, char *argv[])
{
	int i, j;
	float a[1000], b[1000], c[1000], d[1000], e[1000], f[1000];
	
	for (i = 0; i < 1000; i++)
		if (scanf("%f %f %f %f %f %f", &a[i], &b[i], &c[i], &d[i], &e[i], &f[i]) == EOF)
			break;

	for (j = 0; j < i; j++) {
		float x = round((e[j] * c[j] - b[j] * f[j]) / (e[j] * a[j] - b[j] * d[j]) * 100) / 100;
		float y = round((c[j] * d[j] - a[j] * f[j]) / (b[j] * d[j] - a[j] * e[j]) * 100) / 100;

		printf("%.3f ", x == -0.000 ? 0.000 : x);
		printf("%.3f\n", y == -0.000 ? 0.000 : y);

	}

	return 0;
}

Measured memory_bytes: 680
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()
#define MOD 1000000007

int main(){
	string S;
	cin >> S;
	for(int i=0; i<S.size(); i++){
		if(S[i] == 'A') cout << 'T';
		if(S[i] == 'T') cout << 'A';
		if(S[i] == 'C') cout << 'G';
		if(S[i] == 'G') cout << 'C';
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

price = min(A*X+B*Y, C*2 * (max(X, Y)))

is_break = 0

for i in range(100000):
    if price >= A*max(0, X - i) + B*max(0, Y - i)+2*C*i:
        price = A*max(0, X - i) + B*max(0, Y - i)+2*C*i
print(price)


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

using namespace std;

set<int>gr[2][2010];
int depth[2][2010];
int spTab[2][15][2010];

void dfs(int gn, int u, int p, int d)
{
    depth[gn][u] = d;
    spTab[gn][0][u] = p;
    for(int v:gr[gn][u]){
        if(v != p)
            dfs(gn, v, u, d+1);
    }
}
int n;

void fill(){
    for(int gn = 0; gn < 2; gn++){
        for(int i = 1; i < 15; i++){
            for(int j = 1; j <= n; j++){
                if(spTab[gn][i-1][j] != -1){
                    spTab[gn][i][j] = spTab[gn][i-1][spTab[gn][i-1][j]];
                }
            }
        }
    }
}

int lca(int gn, int u, int v){
    if(depth[gn][u] > depth[gn][v]){
        swap(u, v);
    }
    for(int i = 14; i >= 0; i--){
        if(depth[gn][v]-(1<<i) >= depth[gn][u])
            v = spTab[gn][i][v];
    }
    if(u == v)return u;
    for(int i = 14; i >= 0; i--){
        if(spTab[gn][i][u] != spTab[gn][i][v]){
            u = spTab[gn][i][u];
            v = spTab[gn][i][v];
        }
    }
    return spTab[gn][0][u];
}

int dist(int u, int v){
    int d = max(u, v) - min(u, v);
    int l0 = lca(0, u, v);
    int l1 = lca(1, u, v);
    int d0 = depth[0][u] + depth[0][v] - 2*depth[0][l0];
    int d1 = depth[1][u] + depth[1][v] - 2*depth[1][l1];
    return min(d, min(d0, d1));
}

int main()
{
    cin >> n;
    for(int i = 1; i < n; i++){
        gr[0][i].insert(i+1);
        gr[1][i].insert(i+1);
        
        gr[0][i+1].insert(i);
        gr[1][i+1].insert(i);
    }
    int x, y;
    cin >> x >> y;
    gr[0][x].insert(y);
    gr[0][y].insert(x);
    gr[1][x].insert(y);
    gr[1][y].insert(x);
    memset(spTab, -1, sizeof(spTab));
    gr[0][x].erase(x+1);
    gr[0][x+1].erase(x);
    dfs(0, x, -1, 0);
    gr[1][y].erase(y-1);
    gr[1][y-1].erase(y);
    dfs(1, y, -1, 0);
    
    fill();
    vector<int>len;
    len.resize(n);
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            //int d = dist(i, j);
            //cerr << i << " " << j << ": " << d << endl;
          int d = min({j-i, abs(y-j)+1+abs(x-i), abs(y-i)+1+abs(x-j)});
            len[d]++;
        }
    }
    for(int i = 1; i < n; i++){
        cout << len[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<ll> A(N), B(N), C(N);
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < N; j++){
            if (i == 0){
                cin >> A[j];
            }
            else if (i == 1){
                cin >> B[j];
            }
            else {
                cin >> C[j];
            }
        }
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    ll tmpA, tmpC;
    ll ans = 0;

    for (int i = 0; i < N; i++){
        tmpA = distance(A.begin(), lower_bound(A.begin(), A.end(), B[i]));
        tmpC = N - distance(C.begin(), upper_bound(C.begin(), C.end(), B[i]));
        ans += tmpA * tmpC;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2688
#include<iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    int p = 0, sum = 0;
    while (n--) {
        int h; cin >> h;
        if (h > p) sum += h - p;
        p = h;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]    
ab.sort()

# min
if n%2==1:
    med1 = ab[n//2]
    amin=med1[0]
else:
    med1 = ab[(n-1)//2]
    med2 = ab[(n-1)//2+1]
    amin = (med1[0] + med2[0])

ab.sort(key=lambda x: x[1])

# max
if n%2==1:
    med1 = ab[n//2]
    amax=med1[1]
else:
    med1 = ab[(n-1)//2]
    med2 = ab[(n-1)//2+1]
    amax = (med1[1] + med2[1])

if n%2==1:
    print(amax-amin+1)
else:
    print(amax - amin + 1)

Measured memory_bytes: 49092
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffor(i,a,b) for(ll i=a;i<=b;i++)
#define rfor(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//functions: set.insert(val), *(set.find_by_order(order-1)), set.order_of_key(val)

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e6 + 6;
const ll maxN = 1e5 + 6;

ll power(ll x, ll y, ll M = MOD) // default argument
{ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	FIO
	ll x, n; cin >> x >> n;
	ll ar[n];
	ll ans = 0, mmin = INT_MAX;
	ll hash[102] = {};
	FOR(i, n) {
		cin >> ar[i];
		hash[ar[i]] = 1;
	}
	for (ll i = 0; i <= 101; i++) {
		if (hash[i]) continue;
		if (abs(x - i) < mmin || (abs(x - i) == mmin && i < ans)) {
			mmin = abs(x - i);
			ans = i;
		}
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 3648
from collections import defaultdict

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

s = [0]

for i in range(N) :
    s.append((s[-1] + A[i]) % K)
    
for i in range(N + 1) :
    s[i] = (s[i] - i) % K

d = defaultdict(int)

ret = 0
for i in range(min(K, N + 1)) :
    ret += d[s[i]]
    d[s[i]] += 1
for i in range(K, N + 1) :
    d[s[i-K]] -= 1
    ret += d[s[i]]
    d[s[i]] += 1

print(ret)

Measured memory_bytes: 108288
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=[[0]*(s+1) for _ in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
    for j in range(s+1):
        if j+a[i-1]<=s:
            dp[i][j+a[i-1]]+=dp[i-1][j]
            dp[i][j+a[i-1]]%=mod
        dp[i][j]+=dp[i-1][j]*2
        dp[i][j]%=mod
print(dp[n][s])

Measured memory_bytes: 139216
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		int p=mod;
		int ans=0;
		for(int i = 0;i<n;i++) {
			if(a[i]<p){ans++;}
			p=Min(p,a[i]);
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 33116
import java.util.*;

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

		int sum = 999;
		
		List<Integer> subArray = new ArrayList<>();
		
		while(sum != 0) {
			sum = sc.nextInt();
			
			if(sum == 0) {
				break;
			}
			
			int deSum = 0;
			
			for(int i = 0; i < 9; i++) {
				deSum+=sc.nextInt();
			}
			
			subArray.add(sum - deSum);
		}
		
		for(int i = 0; i < subArray.size(); i++) {
			System.out.println(subArray.get(i));
		}
	}
}

Measured memory_bytes: 26268
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
struct node
{
	int v,w;
	node(int vv,int ww)
	{
		v =vv;
		w =ww;
	}
};
vector<node>vt[maxn];
int n,m,indegree[maxn],s[maxn],dilg[maxn];
int a,b,c;
bool topologicalSort()
{
	int num=0;
	queue<int>q;
	
	for(int i=1;i<=n;i++)
	{
		if(indegree[i]==0)q.push(i);
	}
	while(!q.empty())
	{
		int u=q.front();
		s[num++]=u;
		q.pop();
		for(int i=0;i<vt[u].size();i++)
		{ 
			int v=vt[u][i].v; 
			indegree[v]--;
			if(indegree[v]==0)q.push(v);
		}
	}
	
	if(num==n)return true;
	else return false;
}
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%d",&a,&b);
		vt[a].push_back(node(b,1));
		indegree[b]++;
	}
	topologicalSort();
	for(int i=0;i<n;i++)
	{
		int t=s[i];
		for(int j=0;j<vt[t].size();j++)
		{
			int v=vt[t][j].v;
			dilg[v]=max(dilg[v],dilg[t]+vt[t][j].w);
		}
	} 
	printf("%d ",dilg[s[n - 1]]);
	return 0;
}


Measured memory_bytes: 10272
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int ans = min(n, m / 2);
    n -= ans;
    m -= ans * 2;
    if(m > 0){
        ans += m / 4;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

struct ope
{
  /* data */
  int y1;
  int x1;
  int y2;
  int x2;
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> a[i][j];
    }
  }
  vector<ope> o;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W - 1; j++)
    {
      if (a[i][j] % 2 != 0)
      {
        a[i][j]--;
        a[i][j + 1]++;
        o.push_back({i, j, i, j + 1});
      }
    }
  }
  for (int i = 0; i < H - 1; i++)
  {
    if (a[i][W - 1] % 2 != 0)
    {
      a[i][W - 1]--;
      a[i + 1][W - 1]++;
      o.push_back({i, W - 1, i + 1, W - 1});
    }
  }
  cout << o.size() << endl;
  for (auto &it : o)
    cout << it.y1 + 1 << " " << it.x1 + 1 << " " << it.y2 + 1 << " " << it.x2 + 1 << endl;
  int cnt = 0;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (a[i][j] % 2 == 0)
        cnt++;
    }
  }
  cerr << cnt << endl;
  return 0;
}


Measured memory_bytes: 5236
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,sum=0;
	cin>>n;
	long long int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	long long int x=a[0];
	for(long long int i=1;i<n;i++)
	{
		sum = (sum +(a[i]*x))%1000000007;
		x = (x+a[i])%1000000007;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 5188
#include <bits/stdc++.h>
#define ll long long
#define N 300020
#define S 100000
#define M 308
using namespace std;
int n, m, len[N], k[N], res, ms[200002];
int id[N], ans;
ll s[N], t[N];
bool cmp(int x, int y) { return t[x] < t[y]; }
int prime[N], snum = 325, pnum;
bool p[N];
void EulerSieve(int n) {
    for (int i = 2; i <= n; i++) {
        if (!p[i]) prime[++pnum] = i;
        for (int j = 1; j <= pnum; j++) {
            if (i * prime[j] > n) break;
            p[i * prime[j]] = true;
            if (i % prime[j] == 0) break;
        }
    }
}
int main() {
    EulerSieve(S);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &s[i]);
        k[i] = len[i] = 0, t[i] = 1;
        for (int j = 1; j <= M; j++) {
            if (s[i] % prime[j]) continue;
            int m = 0;
            while (s[i] % prime[j] == 0) s[i] /= prime[j], m++;
            if (m %= 3) k[i] |= ((m & 1) << len[i]), len[i]++, t[i] *= prime[j];
        }
        if (s[i] > 1) {
            if (s[i] < S)
                k[i] |= (1 << len[i]), len[i]++, t[i] *= s[i];
            else {
                ll ss = sqrt(s[i]);
                if (ss * ss != s[i])
                    ans++, i--, n--;
                else
                    len[i]++, t[i] *= ss;
            }
        }
    }
    for (int i = 1; i <= n; i++) id[i] = i;
    sort(id + 1, id + n + 1, cmp);
    for (int l = 1, r = 1; l <= n; l = r + 1, r = l) {
        while (r < n && t[id[r]] == t[id[r + 1]]) r++;
        if (t[id[l]] == 1) {
            ans++;
            continue;
        }
        int maxn = (1 << len[id[l]]) - 1;
        for (int i = l; i <= r; i++) ms[k[id[i]]]++;
        for (int i = l; i <= r; i++) {
            int x = k[id[i]], ot = (maxn ^ k[id[i]]);
            if (ms[x] >= ms[ot]) ans += ms[x], ms[x] = ms[ot] = 0;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 9216
#include "bits/stdc++.h"
using namespace std;
// http://arc076.contest.atcoder.jp/tasks/arc076_a
typedef long long ll;
const ll MOD = 1e9 + 7;
void init_fac(ll x, vector<ll>&fac) {
	fac[0] = 1;
	for (int i = 1; i < x; i++) {
		fac[i] = (fac[i - 1] * i) % MOD;
	}
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, M; cin >> N >> M;
	if (abs(N - M) > 1) { cout << 0 << endl; return 0; }
	vector<ll> fac(max(N, M) + 1, 0);
	init_fac(max(N, M) + 1, fac);
	ll ans;
	if (N == M) {
		ans = ((fac[N] * fac[M]) % MOD * 2) % MOD;
	}
	else {
		ans = (fac[N] * fac[M]) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, M;
vi S, T;
vv<ll> dp;
const int Max = 1e5;

int main() {
    cin >> N >> M;
    S.resize(N);
    T.resize(M);
    rep(i, N) cin >> S[i];
    rep(i, M) cin >> T[i];

    dp = vvec(N + 1, M + 1, 0LL);
    dp[0][0] = 0;
    vll suf_T(Max + 1);

    rep(i, N) {

        rep(j, M) {
            if (S[i] == T[j]) {
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i + 1][j]) % MOD;
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j + 1]) % MOD;
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + 1) % MOD;
            }
            else {
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i + 1][j]) % MOD;
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j + 1]) % MOD;
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] - dp[i][j] + MOD) % MOD;
            }
        }
    }

    ll ans = dp[N][M] + 1;
    write(ans);
}

Measured memory_bytes: 32384
#include<stdio.h>
int main()
{
	char a[5];
	while(~scanf("%s",a))
  {
	getchar();
	int i,t=0;
	for(i=0;i<3;i++)
	 {
	 	if(a[i]==a[i+1])
	 	t=t+1;
	 }	
	 if(t==0)
	 printf("Good\n");
	 else 
	 printf("Bad\n");
   }
	 return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String argv[])
    {
	Scanner scan = new Scanner(System.in);
	int x,y;

	while(true)
	    {
		x = scan.nextInt();
		y = scan.nextInt();
		if( x == 0 && y == 0 )
		    break;
		else if( x <= y)
		    System.out.println(x+" "+y);
		else if( x > y )
		    System.out.println(y+" "+x);
	    }
    }
}

Measured memory_bytes: 35728